Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 如何在rails 4.1中使用按钮_单击事件_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 如何在rails 4.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_

我是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_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]}