5

I'm learning how to build rails applications and I still do not fully understand how to make buttons do stuff. How do I make a particular method run using the attributes supplied in a form?

1 Answer 1

9
<%= button_to "Acknowledged", { :controller => 'practice_sessions',
  :id => @practice_session.id}, 
  :method => :put %>

from https://stackoverflow.com/a/4198918/643500

Read http://edgeguides.rubyonrails.org/getting_started.html

More Examples

<%= button_to "New", :action => "new" %>
# => "<form method="post" action="/controller/new" class="button_to">
#      <div><input value="New" type="submit" /></div>
#    </form>"

<%= button_to "New", :action => "new", :form_class => "new-thing" %>
# => "<form method="post" action="/controller/new" class="new-thing">
#      <div><input value="New" type="submit" /></div>
#    </form>"

<%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %>
# => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
#      <div><input value="Create" type="submit" /></div>
#    </form>"

<%= button_to "Delete Image", { :action => "delete", :id => @image.id },
          :confirm => "Are you sure?", :method => :delete %>
# => "<form method="post" action="/images/delete/1" class="button_to">
#      <div>
#        <input type="hidden" name="_method" value="delete" />
#        <input data-confirm='Are you sure?' value="Delete" type="submit" />
#      </div>
#    </form>"

from http://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.