【问题标题】:Styling Rails button link helpers with Twitter Bootstrap使用 Twitter Bootstrap 设计 Rails 按钮链接助手
【发布时间】:2012-03-31 02:48:41
【问题描述】:

我正在使用 Rails 助手来生成按钮,并且我正在尝试使用按钮的 Twitter 引导样式来设置按钮的样式。我添加了带有:html 选项的类。页面没有中断,但样式没有显示。

<%= button_to('Sign Up', new_user_registration_path, :html => {:class => 'btn.btn-large.btn-primary'})  %>
<%= button_to "Sign Up", user_omniauth_authorize_path(:facebook), :html => {:class => 'btn.btn-large.btn-primary'} %>

这是 facebook 按钮的页面源代码

<form action="/users/sign_up" class="button_to" method="post"><div><input html="{:class=&gt;&quot;btn.btn-large.btn-primary&quot;}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>
<form action="/users/auth/facebook" class="button_to" method="post"><div><input html="{:class=&gt;&quot;btn.btn-large.btn-primary&quot;}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>

知道我做错了什么吗?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap


    【解决方案1】:

    您只需要:class =&gt; "foo" 来设置按钮的类,而不是:html =&gt; { :class =&gt; "foo" }。所以它应该是这样的:

    <%= button_to('Sign Up', new_user_registration_path, :class => 'btn btn-large btn-primary')  %>
    

    这将生成您的大主按钮。

    【讨论】:

    • 我用一张图片更新了 OP,显示了类是如何附加到输入元素的。有什么线索吗?
    • 它需要类之间的空格 :class=> 'btn btn-large btn-success' 它是这样工作的。
    • Twitter 引导程序使用空格而不是点。我已经提交了对原始帖子的修改,但需要先获得批准。
    【解决方案2】:

    上面的答案对我来说已经接近修复,但需要将button_to 更改为link_to。也摆脱了火箭...=&gt;

    <%= button_to('Sign Up', new_user_registration_path, class: 'btn btn-large btn-primary')  %>
    

    【讨论】:

    • 我的意思是,哈希火箭应该仍然可以工作,这只是一个语法问题。但是不知道将button_to 更改为link_to 是什么意思,因为您的sn-p 甚至没有link_to
    猜你喜欢
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 2013-05-29
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多