Formtastic设置类和表单的id

时间:2010-01-12 07:57:52

标签: ruby-on-rails forms

如何通过semantic_form_for?

设置表单元素的class和id属性

以下代码:

<% semantic_form_for (@meetingsearch), :class => "new_meeting_search", :id => "meeting_search" do |f| %>

给了我:

<form action="/meetingsearches" class="formtastic meetingsearch" id="new_meetingsearch" method="post"> 

1 个答案:

答案 0 :(得分:61)

这应该做你需要的(未经测试):

<% semantic_form_for @meetingsearch, :html => { :class => "new_meeting_search", :id => "meeting_search" } do |f| %>

为了澄清,semantic_form_for包含了form_for中内置的Rails',所以这正是您在regular Rails forms also中执行此操作的方式:

<% form_for @meetingsearch, :html => { class => "new_meeting_search", :id => "meeting_search" } do |f| %>