rails 3: display link as button?

前端 未结 4 1535
太阳男子
太阳男子 2020-12-08 02:10

On some non-form pages, I have a few links that would look better as a button than a hyperlink...

I thought button_to instead of link_to would work, but buton_to see

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 02:53

    I recently had to do this because my form was acting differently for link_to than it was with button_to and I needed the functionality the link provided. The best solution I found does not use CSS at all but instead calls .html_safe to escape the html in the ruby code and properly display the link as a button. What you want to do is this:

    <%= link_to "".html_safe, some_path, :id => "button_id", :class => "button_class" %>
    

提交回复
热议问题