在Rails中从索引页面提交表单

时间:2011-08-19 11:27:44

标签: ruby-on-rails ruby-on-rails-3 forms

我是Rails新手。

如何制作一个允许用户通过Home#Index View中的单选按钮选择语言(en,fr等)以提交到Home#Language动作的表单?

提前致谢

1 个答案:

答案 0 :(得分:3)

<%= form_tag language_path, :method => :post do %>
  <%= label_tag :language_english, 'English' %>
  <%= radio_button_tag :language, 'english' %>
  <%= label_tag :language_french, 'French' %>
  <%= radio_button_tag :language, 'french' %>
  <%= submit_tag %>
<% end %>

language_pathroutes.rb中定义的路径,例如

match "/home/language" => "home#language", :as => 'language'