MenusController无法找到动作'74'

时间:2014-08-30 06:56:18

标签: ruby-on-rails-4

menuList.html.erb

<%= link_to("Edit",{:action=>'edit',:id=>menu.id})%>

menus_controller

def edit
    @menu=Menu.find(params[:id])    
end

def update
   @menu=Menu.find(params[:id])
   if @menu.update_attributes(menu_params)     
       flash[:notice]="Menu Updated Successfully"    
   else
       endrender('edit')
end
end
def menu_params
    params.require(:menu).permit(:menu_item_name,:price,:item_type,:image)
end
menus/edit中的

<%= form_for(:menu,:url=>{:action=>'update',:id=>@menu.id}) do |f|%>.....

我面临的问题:

  1. 当我点击Edit并访问编辑页面时,我收到了错误的网址'../menus/74/edit',我认为应该是'../menus/edit/ 74' 。

  2. 点击Save Edit后,我收到The action '74' could not be found for MenusController。请帮助我,我是新手。

1 个答案:

答案 0 :(得分:0)

在config / routes.rb中添加如下内容:

resources :menu do
 member do
   get 'edit' # or post or any other method as per your need
 end
end

有关编辑路线的参考:http://guides.rubyonrails.org/routing.html