Ruby on rails 4 如何在rails 4.1中使用按钮_单击事件
我是rails新手。我想知道如何使用Rails4.1中的点击事件。 在控制器的菜单中:Ruby on rails 4 如何在rails 4.1中使用按钮_单击事件,ruby-on-rails-4,Ruby On Rails 4,我是rails新手。我想知道如何使用Rails4.1中的点击事件。 在控制器的菜单中: def index @menus=Menu.where(:hotel_id=>@hotel.id).sorted @cart = current_cart if :MEAL @menus=Menu.where(:hotel_id=>params[:hotel_id],:item_type=>'Meal').sorted @cart = current_
def index
@menus=Menu.where(:hotel_id=>@hotel.id).sorted
@cart = current_cart
if :MEAL
@menus=Menu.where(:hotel_id=>params[:hotel_id],:item_type=>'Meal').sorted
@cart = current_cart
end
在菜单/索引中:
'menus',:action=>'index',:hotel_id=>params[:hotel_id]},class:'linkstyle')%>
使用上述代码后,页面将被重定向到菜单#create
,为什么会发生这种情况?
在索引页面中,我有这个按钮,单击这个按钮后,我想停留在同一页面中,这个按钮将调用控制器中索引方法中的if块。应该是
(“膳食”,“控制器”,“菜单”,“菜单”,“操作”,“索引”,“酒店id=”参数[:酒店id]},
{:controller=>“菜单”,“操作”,“酒店id=”参数[:酒店id]}
使用此选项后,页面仍会重定向到菜单35;创建
。如果块也不起作用。如果您在某个控制器中,则只使用{:操作=>'index',:hotel_id=>params[:hotel_id]}