在rails中为FormTagHelper提供特定ID

时间:2012-10-29 14:03:13

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

我有一个用 HAML 文件写的表格,就像这样

= form_tag "ratings_form", movies_path, :method => :get do
  Include: 
  - @all_ratings.each do |rating|
    = rating 
    = check_box_tag "ratings[#{rating}]", 'yes', @ratings.keys.include?(rating)
  = submit_tag 'Refresh'

我想给每个表单提交按钮一个特定的 id

我检查了documentation并发现了给

的参数

form_tag submit_tag 不包含ID。


正确的答案是添加:id => “id_u_want”到任何标签,显然它会起作用 它在我做的时候起作用了

= form_tag movies_path, :id => "ratings_form" , :method => :get do
  Include: 
  - @all_ratings.each do |rating|
    = rating 
    = check_box_tag "ratings[#{rating}]", 'yes', @selected_ratings.keys.include?(rating)
  = submit_tag 'Refresh' , :id => "ratings_submit"

1 个答案:

答案 0 :(得分:1)

尝试:id=>"someid"看看它是否适合你。