繁体   English   中英

如何在Rails的Form_Tag中添加class和fontawesome图标

[英]How to add class and fontawesome icon to Form_Tag in rails

我正在尝试将超赞的表单标签和字体添加到以下格式:

<%= form_tag(controller: "maps", action: "favorite", method: "post"%>
      <%= submit_tag "Favorite"%>

我已经尝试过这种方式,但没有任何反应,仍然看起来像下面图片中的灰色按钮。 我正在尝试替换图像中具有字体真棒图标的绿色“收藏夹”按钮。

<%= form_tag(controller: "maps", action: "favorite", method: "post")%>
      <%= submit_tag "Favorite",html: { class: 'btn-u btn-u-lg rounded-4x btn-u-green' }%>

这是我的完整代码和图像:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!--Basic Table-->
        <div class="panel panel-green margin-bottom-40">
            <div class="panel-heading">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <div class = "name"></div>
            </div>
            <div class="panel-body">
                <div id="map2" style='width: 568px; height: 365px;'></div>
                <div class="row">
                    <div class="col-sm-12 text-center">
                        <button class="btn-u btn-u-lg rounded-4x btn-u-green" type="button"><i class="fa fa-check-circle" aria-hidden="true"></i> Check Availability</button>
                        <button class="btn-u btn-u-lg rounded-4x btn-u-green" type="button"><i class="fa fa-plus-circle" aria-hidden="true"></i> Add to Favorites</button>

                        <%= form_tag(controller: "maps", action: "favorite", method: "post")%>
                            <%= submit_tag "Favorite",html: { class: 'btn-u btn-u-lg rounded-4x btn-u-green' }%>

                    </div>
                </div>
            </div>
            <table class="table paneltb">
            </table>
        </div>
        <!--End Basic Table-->
    </div>
</div>

表单标签

对于其他可能会偶然发现此问题的人,我认为不可能将带有字体的精美图标与form_tag链接。 我能够通过link_to标记来做到这一点。

在上面的示例代码Jermaine Subia中,我认为它看起来像这样:

<%= link_to(favorite_maps_path, method: "post") do %>
   <i class="fa fa-heart" title="Favorite"></i>
<% end %>

这是一些我刚刚实现的示例代码,我知道它们可以工作:

 <%= link_to(user_jobs_path(user_job: {title: job.title, company: job.company, url: job.url, description: job.description, user_id: current_user}), method: "post") do %>
     <i class="fa fa-heart" title="Save to my jobs"></i>
 <% end %>

同样在上面的示例中,我向动作传递了许多参数,并且顺便说一句,您不需要title属性,我认为这只是将鼠标悬停在图标上时看到的文本。 希望这可以帮助某人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM