RoR ruby -- undefined method `model_name' for NilClass:Class -
i'm having trouble update on class.
this view:
<div id = "list"> <%= form_for @list |form| %> <%= render 'shared/error_messages', object: form.object %> <div class="list_fields"> <%= form.text_field :name, placeholder: and controller:
def update if @list.update_attributes(params[:list]) flash[:success] = "list updated" else render 'edit' end redirect_to @list end the routes are:
resources :lists, only: [:create, :show, :destroy,:edit] now problem keeps raising
"undefined method `model_name' nilclass:class" in line 2 ---> <%= form_for @list |form| %> and can't seem figure out why. in advance leo
you have load @list before update attributes.
def update @list = list.find_by_id(params[:id]) if @list.update_attributes(params[:list]) flash[:success] = "list updated" else render 'edit' end redirect_to @list end and way, problem see not caused update action edit action redirects view.
you have load @list in both actions. in edit action in order render view, in update action in order update appropriate object.
Comments
Post a Comment