button button f
Communities for your favorite technologies. Explore all Collectives
TeamsNow available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat.
Learn more Explore Teams TeamsAsk questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsGet early access and see previews of new features.
Learn more about LabsI'm new to rails, and just found the simple_form gem. I installed it with bootstrap suport, but now I can't get this code to work the way I want it
%= f.button :submit, " i class='icon-ok icon-white' /i Save", class: "btn btn-primary" %I just want to put the icon inside the button, but when I do this, it shows me a button with the text ' i class='icon-ok icon-white' /i Save'
I also tried to do
%= f.button :submit, class: "btn btn-primary" do % i class="icon-ok icon-white" /i Save % end %But with no success. How can I add some HTML inside the button with simple_form gem?
ruby-on-rails ruby twitter-bootstrap simple-form Share Improve this question Follow edited May 6, 2015 at 13:29 Ismael 16.7k 6 6 gold badges 62 62 silver badges 76 76 bronze badges asked Jun 1, 2012 at 23:37 Bruno Campos Bruno Campos 2,188 1 1 gold badge 20 20 silver badges 34 34 bronze badges Add a comment |Don't use content_tag. The following works:
%= button_tag(type: 'submit', class: "btn btn-primary") do % i class="icon-ok icon-white" /i Save % end % Share Improve this answer Follow answered Jun 5, 2012 at 14:24 Undistraction Undistraction 43.7k 62 62 gold badges 202 202 silver badges 334 334 bronze badges 8 1 Even if this solution works, I don t like it because I can t see the f variable anymore :( – Cyril Duchon-Doris Commented Nov 23, 2014 at 23:44 1 @CyrilDD Why do you need to see the form builder so badly? All it is is a collection of methods to simplify building a form, using a model or class as reference. A submit button has no need to know about the model s structure like inputs do, so there is actually little reason to use the builder. Unfortunately Rails s handling of most of the view tier is a complete disaster and woefully in need of updating. There are far bigger issues. – Undistraction Commented Nov 24, 2014 at 0:48 I don t need it so badly . It s just tha in my code, I have many %= f.something % and for some reason a %= button_tag % shows up. Somewhat ugly. However, this (may ?) become a real problem for submitting nested forms – Cyril Duchon-Doris Commented Nov 24, 2014 at 0:50 @CyrilDD It s not a problem with nested forms, as you are actually submitting a single form with a single submit button. No matter how nested it is, it s just clever use of a single form. Take a look at the rendered form. You ll see all the nesting is just encoded into the name attributes of the inputs and decoded at the other end. – Undistraction Commented Nov 24, 2014 at 0:52 But what about forms inside forms ? Then we d want to know which form we want to send (though I can t think of any scenario where one would do this maybe if we just want to post a subset of changes ?) – Cyril Duchon-Doris Commented Nov 24, 2014 at 1:05 | Show 3 more comments 27In simple_form 3.0rc use :button button type (it passes your block to original ActiveView button helper):
%= f.button :button do % i class="icon-save" /i Commit % end %Or write additional button wrapper.
For additional info look into simple_form/form_builder.rb FormBuilder#button method.
Share Improve this answer Follow answered Aug 28, 2013 at 13:14 Bombazook Bombazook 495 4 4 silver badges 14 14 bronze badges 5 Tried it, doesn t work. Writing a button wrapper sounds like a good idea, though. – Andrew Smith Commented Sep 1, 2013 at 13:29 For some reason this only works with :button, and not :submit. I m using 3.1rc2 – Petercopter Commented Sep 25, 2014 at 22:33 When you use button method it passes your block to #{type}_button or #{type} helper. Simple form button helpers doesn t support blocks so using button_button helper that declared as alias_method :button_button, :button we call original method from ActionView::Helpers::FormBuilder . With :submit button type it s not possible. Read code of simple_form/form_builder.rb for better explanation. – Bombazook Commented Sep 29, 2014 at 14:41 this works, and should be the actual answer that solves it since it uses simple_form methods. – Andrew Commented Sep 21, 2015 at 19:40 This should be the accepted answer. github.com/plataformatec/simple_form#buttons – Erowlin Commented Aug 4, 2017 at 7:26 Add a comment | 7I think you can't do it with simple_form. But I have good news for you. You should be fine using rails helper along side with simple form.
just do
button_tag(type: 'submit', class: "btn btn-primary") do content_tag(:i, class: "icon-ok icon-white") "Save" endNot sure if this works, even the syntax but it should give you a hint
Share Improve this answer Follow edited Nov 7, 2013 at 22:22 answered Jun 2, 2012 at 2:09 Ismael Ismael 16.7k 6 6 gold badges 62 62 silver badges 76 76 bronze badges Add a comment | 1You can do this with the following code:
= f.button :button, 'Send', data: { disable_with: " i class='fi-heart' /i Sending " }Note that you want to use f.button instead of f.submit Also note that :button needs to be the first param to f.button
Share Improve this answer Follow answered Jun 25, 2016 at 13:34 stephenmurdoch stephenmurdoch 34.5k 29 29 gold badges 118 118 silver badges 193 193 bronze badges 1 1 Also note that :button needs to be the first param thats solved my problem. i tried using :submit, which didn t work! it didn t parse the text to html, but when i changed to :button it worked perfectly. thanks – Ziv Galili Commented Dec 15, 2016 at 16:14 Add a comment |To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
lang-rbSite design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.23.15701