ruby - How to insert data in product table with user id rails 4 -
hello absolute newbie in rails. creating application stuck on point.
the problem want insert data in products per user id saying:
uninitialized constant productcontroller
here route file:
rails.application.routes.draw #devise_for :users devise_for :users, :controllers => { :registrations => 'users/registrations' } resources :dashboard root to: "home#index" namespace :user resources :users end resources :product end here product controller i.e, product_controller.rb:
class product::productcontroller < applicationcontroller def new @product = product.new end def create @product = product.new(params[:product]) if @product.save flash[:success] = "product added" redirect_to product_index_path else flash[:success] = @product.errors.full_messages.join redirect_to :back end end end and here new.html.erb code:
<h2>add product</h2> <%= form_for(resource, :as => resource_name, :url => user_registration_path) |f| %> <div class="field"> <%= f.label :product_name %><br /> <%= f.text_field :product_name, autofocus: true %> </div> <%= p.hidden_field :user_id, :value => current_user %> <div class="actions"> <%= f.submit "add product" %> </div> <% end %> <% end %> i know thing wrong too:
<%= form_for(resource, :as => resource_name, :url => user_registration_path) |f| %> how can make parts one? goal take use new page add product name , redirect product list page.
rename controller products_controller.rb
then change
class product::productcontroller < applicationcontroller ------------- end to
class product::productscontroller < applicationcontroller ------------- end even routes needs changed. if want products controller inside namespace product mentioned in question, have declare routes shown below.
namespace :product resources :products end
Comments
Post a Comment