我想将params从一个视图传递到另一个视图。在我的index.html.erb我有一个空div:控制器没有在rails中调用
index.html.erb:
<div id="main"> </div>
首先我通过以下加载侧栏内的main.html.erb文件链接:
side.html.erb
<%= link_to image_tag('btn_next.png'), home_main_path(:game_id=>item.game.id), :remote => true %>
这是我的加载文件main.html.erb进入主DIV 。下面是一些代码:
main.js.erb
$("#main").html("<%= escape_javascript render(:file => 'home/main.html.erb', :handlers => [:erb]) %>");
home_controller.rb
def main
puts 'main called'
...
日志
main called
Started GET "/home/main?game_id=1" for 127.0.0.1 at 2016-02-15 18:54:37 +0100
Processing by HomeController#main as JS
Parameters: {"game_id"=>"1"}
Ë一切都很好。现在,该main.html.erb里面我有一个链接到一个game_main.html.erb文件:
main.html.erb
<%= link_to I18n.t('basic.game_statistic'), home_game_main_path(:game_id => @game.id, :mode => 'GameGoals'), :remote => true, :class => "main" %>
这里的game_main链接一些代码:
game_main.js.erb
$("#main").html("<%= escape_javascript render(:file => 'home/game_main.html.erb', :handlers => [:erb]) %>");
home_controller.rb
def game_main
puts 'game_main called'
...
html文件被加载到main-div中。但是game_main-controller没有被调用。我的日志:
日志
Started GET "/home/game_main?game_id=1&mode=GameGoals" for 127.0.0.1 at 2016-02-15 19:13:19 +0100
Processing by HomeController#game_main as JS
Parameters: {"game_id"=>"1", "mode"=>"GameGoals"}
不通知 'game_main称为'。所以我无法获得参数。什么地方出了错?我能够处理HomeController#main,但不能处理HomeController#game_main。
感谢您的帮助。
拉尔斯
P.S:我的路线:
路线。RB
match '/home/main', :to => 'home#main'
match '/home/game_main', :to => 'home#game_main'
耙路线
home_main /home/main(.:format) home#main
home_game_main /home/game_main(.:format) home#game_main
但它与main.html.erb文件?!任何建议如何编码? – Lars
我试着用<%= link_to I18n.t('basic.game_statistic'),home_game_main_path(:game_id => @ game.id,:mode =>'GameGoals'),方法:: get,:controller =>: home_controller,:action =>:game_main,:remote => true,:class =>“main”%> - 不工作 – Lars