Rails 如何给 form_tag 加 css,rails3?

087796 · 2012年03月22日 · 最后由 087796 回复于 2012年03月22日 · 3911 次阅读

请教:如何给 form_tag 定制的 css?说明:rails3.2,使用 twitter bootstrap-sass。form_for 是没有问题的,bootstrap 的效果都有。

代码如下:

<div class="row">
  <div class="span6 offset3 well">
    <%= form_tag({:controller => "admin/projects", :action => "search"}, :method => "get") do %>

          <%= label_tag(:year, "按年度查询:") %>
          <%= text_field_tag(:year, ) %>

          <%= label_tag(:number, "按编号查询:") %>
          <%= text_field_tag(:number) %>

        <%= submit_tag "Search", :class => "btn btn-large btn-primary"  %>
    <% end %>
  </div>
</div>

在 form_tag 上使用了如下,但没有效果:

<%= form_tag({:controller => "admin/projects", :action => "search"}, :method => "get",:class => "form-inline" do %>

 <%= submit_tag "Search", :class => "btn btn-large btn-primary"  %>

button 的前端展现,调用了 bootstrap。

<%= form_tag({:controller => "admin/projects", :action => "search"},{ :method => "get",:class => "form-inline"} do %> 这样试一下

<% form_tag url(:subusers, :index, user_id:@user_id ), method:'get', class:'form-inline' do %>

feichan:之前也这样试过,不行....

楼主试试看这样:

<%= form_tag url_for(:controller => "admin/projects", :action => "search"), :method => "get", :class => "form-inline" do %>
<% end -%>



<%= form_tag({:controller => "admin/projects", :action => "search"}, :method => "get", :html => {:class => "form-inline" } do %>

 <%= submit_tag "Search", :class => "btn btn-large btn-primary"  %>

#5 楼 @Rei 你确定这个能在 Rails 3 下面工作嘛? 我测试了下不行,我查了下最新源码,form_tag_html中用 view helper 的tag方法 (tag_options) 也已经不对 options 中的html作特别处理了吧。

#6 楼 @lgn21st 我也不确定~

顶楼 form_tag 的右半括号去哪了?

5 楼 rei, 6 楼 lgn21st: 你们的方法,rails3 下,我都试过,统统不起作用..

#5 楼 @Rei 不起作用滴

#12 楼 @87796 有什么错误提示么?我是在自己的 Rails 3.1.1 里面贴了这端代码,测试过才发布到 4 楼的。

#13 楼 @lgn21st 谢谢!你提供的 code,运行时没有错误的。但挂上的 form-inline 没起作用啊。实在不行,用 form_for 了..:-(。耽误好一会了,晚上有时间再找 solution 了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号