简体   繁体   中英

How to add class and fontawesome icon to Form_Tag in rails

I am trying to add a form tag and font awesome to the following format:

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

I have tried it this way and nothing is happening it still looks like the grey button in the picture below. I am trying to replace the green favorite button in the image that has a font awesome icon as well.

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

Here is my full code and the image:

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

表单标签

For others who might stumble across this, I don't think it is possible to link a font awesome icon with a form_tag. I was able to do this with a link_to tag.

In the sample code Jermaine Subia asked about above I think it would look like this:

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

Here is some sample code I have just implemented that I know works:

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

Also in the example above, I am passing a number of params to the action and as an aside you shouldn't need the title attribute, I think this is just text you see when you hover over the icon. Hope this helps someone out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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