ruby on rails - undefined method `update_attributes' for nil:NilClass when updating object -
I get the error "undefined method" update_attributes' for zero: when I try to update my page object I know I have confirmed that @page is empty, but I can not know why?
def new @ page = page. News @ topic = topic Order ('Status ASC') @ Page_count = Page.count + 1 end Make DEF @ Page = Page.New (page_ups) if @ Page. Think flash [: notice] = 'New page added!' Redirect_to Action: 'Index' and @subjects = Subject.order ('Status ASC') @page_count = Page.count + 1Render 'New' End and Edit Edit @page = Page.find_by (id: params [: id] ) @subjects = Subject.order ('Status ASC') @page_count = Page.count End Def Update @page = Page.find_by (id: params [: id]) If @page.update_attributes (page_params) flash [: notice] = 'The page has been updated!' Redirect_to Action: 'Show', ID: @ Page.id other @ thematic = subject. Order ('Status AS') @page_count = Page.count 'Edit' End-End Personal DF Page on Parameters Parameters (. (: Subject_id ,: name ,: permalink,: position,: visible) end routes: match ': controller (/: action (/: id))' ,: by = & gt; [: Get, post]
make sure params [: id ] is not empty, you can see your thoughts for it, then you can use search by ID, and in case of any record usage, object 's #try Method: @page = page .find_by_id (params [: id]) If @page.try (: update_attributes, page_params) ...
Comments
Post a Comment