【问题标题】:How to add class and fontawesome icon to Form_Tag in rails如何在rails中将类和字体图标添加到Form_Tag
【发布时间】:2023-03-26 23:10:01
【问题描述】:

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

<%= 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>

【问题讨论】:

  • 你安装了 font-awesome-rails gem 吗?
  • 是的,我确实安装了它
  • 尝试删除 html: {} 部分。
  • 试试这个
  • @xiaocui 字体真棒图标怎么样?

标签: html css ruby-on-rails font-awesome


【解决方案1】:

对于可能偶然发现这一点的其他人,我认为不可能将字体真棒图标与 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 属性,我认为这只是您将鼠标悬停在图标上时看到的文本。希望这可以帮助某人!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多