ruby on rails - undefined method `model_name' for NilClass:Class on view -


my code working on local server it's not working on production server. can't figure out i'm doing wrong.please me.

this i'm getting error in partial:

 <%=form_for @shiftchange, :url => { :controller=>"schedulers" ,:action => "shift_change" },:validate=>true , :method => :post |f|%>         <%= f.label :from_date , "from date " %>        <%= f.text_field :from_date ,:class =>'datepicker' %>    <% end %> 

to load partial,this i'm doing this:-

<%= render "schedule_shift" %> 

in controller have this:

@shiftchange = shiftchange.new 

if form included multiple actions (pages) need set @shiftchange or form_for directive fail (it won't have create form for).

a better approach (and rails default) have separate views each action, each including elements required action, , loaded application.html.erb layout <%= yield %>. have app/views/shiftchanges/new.html.erb view has form in it. never need define load paths in rails, derived model, controller , action names - or routes.rb. core part of convention on configurationhttp://en.wikipedia.org/wiki/convention_over_configuration paradigm runs deep in rails.

if need have form creating new object on every page (often used shiftchangesessions example), can rewrite form_for doesn't depend on object being present:

form_for(shiftchange.new) 

or if need force post create method

form_for(shiftchange.new, :url => { :action => "create" })  

you can read more resource driven form_for in ruby on rails api docs http://api.rubyonrails.org/classes/actionview/helpers/formhelper.html#method-i-form_for-label-resource-oriented+style.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -