forms - Ruby on Rails: undefined method `' for #<#<Class:>> -


i'm relatively new rails , i've been struggling couple of days. i'd appreciated if can see i've gone wrong.

when view page in web browser following message:

showing c:/users/matt/documents/github/outputer/app/views/studies/index.html.erb line #8 raised:

undefined method `studies_path' #<#:0x6b03808>

8: <%= form_for @new_study |f| %>

studies_controller:

def index     @line = current_user.lines.find_by_id(params[:line_id])       @machine = @line.machines.find_by_id(params[:machine_id])       @studies = @machine.studies.paginate(page: params[:page], :per_page => 10)     @new_study = @machine.studies.build end  def create     @study = current_user.lines.machines.study.build(params[:study])     if @study.save         flash[:success] = "study created"       else         flash[:error] = "error : invalid study description"       end     redirect_to :back end 

index.html

.... <section> <%= form_for @new_study |f| %>     <div class="field">         <%= f.text_field :description, placeholder: "new study description..." %>     </div>     <%= f.submit "create", class: "btn" %> <% end %> </section> .... 

study model

.... class study < activerecord::base     belongs_to :machine     belongs_to :line     attr_accessible :avg_speed, :avg_uptime, :avg_yield, :description, :duration, :is_active, :start_time, :stop_time, :line_id      validates ....      has_many :events, dependent: :destroy     .... end .... 

rake routes:

.... save_line_machine_study put    /lines/:line_id/machines/:machine_id/studies/:id/save(.:format) studies#save {:has_many=>:machines} line_machine_studies       /lines/:line_id/machines/:machine_id/studies(.:format)          studies#index {:has_many=>:machines}                         post   /lines/:line_id/machines/:machine_id/studies(.:format)          studies#create {:has_many=>:machines} new_line_machine_study     /lines/:line_id/machines/:machine_id/studies/new(.:format)      studies#new {:has_many=>:machines} edit_line_machine_study    /lines/:line_id/machines/:machine_id/studies/:id/edit(.:format) studies#edit {:has_many=>:machines} line_machine_study         /lines/:line_id/machines/:machine_id/studies/:id(.:format)      studies#show {:has_many=>:machines}                         put    /lines/:line_id/machines/:machine_id/studies/:id(.:format)      studies#update {:has_many=>:machines}                         delete /lines/:line_id/machines/:machine_id/studies/:id(.:format)      studies#destroy {:has_many=>:machines} .... 

routes.rb

resources :users resources :lines, :has_many => :machines,  only: [:index, :edit, :destroy, :show, :create]     resources :machines, only: [:new, :create, :edit, :update]         resources :studies      end end 

if remove form page works fine suggest in form. i've tested controller commands in console , appear fine - can create new study object.

thanks in anticipation

when use form_for model instance, defaults post action controller studies_path. mapped create in controller.

from looks of it, need add route in routes.rb handle post request (see resources). need create method in studies controller.

here guide learning basics of routing in rails.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -