Ruby on Rails - link_to button / css

前端 未结 3 922
南旧
南旧 2020-12-24 01:28

Ok so I am teaching myself RoR while developing a simple api & web interface. I have been following a number of guides and testing out different outcomes. I have mocke

相关标签:
3条回答
  • 2020-12-24 01:51

    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 "<button>Add</button>".html_safe, new_admin_course_path, :id=>"open-contacts-dialog-btn", :class=>"inbox-sf-add-btn tip" %>
    
    0 讨论(0)
  • 2020-12-24 02:02

    link_to generates a <a> tag, which is not input type="submit". What you should use should be a button_to, which generates a form with a input type="submit" button to the link:

    <%= button_to "Add", new_admin_course_path, :id => "open-contacts-dialog-btn",
          :class => "inbox-sf-add-btn tip", :method => :get %>
    

    Note the :method => :get. Without it, the button_to will generate a form with method set to post.

    0 讨论(0)
  • 2020-12-24 02:09

    But it is not adding my CSS styling
    What do you mean? The link (a element) with classes inbox-sf-add-btn and tip is generated, right? So, what's the problem?

    If you want strictly button (input element instead of a), you can specify /book/new (or <%= new_admin_course_path %>) in the action attribute of your html form (form element).

    0 讨论(0)
提交回复
热议问题