Reputation: 30648
Here is the code for generate button, but I want it in a hyper text, how to modify this?
<% form_remote_tag (:url => { :action => :choose_category, :id => category }) do %>
<%= submit_tag category.name %>
<% end %>
I tried to use the link_to
, but it can't submit a post method, what can I do?
Upvotes: 0
Views: 78
Reputation: 591
If I understand correctly, you want replace the submit button in your posted code with a regular hyperlink (<a>
tag). Check out link_to_remote. To understand the javascript code that generates, you may also want to check out the docs for Prototype's Ajax.Updater.
Upvotes: 2
Reputation: 30452
Links can't technically submit forms. That means you're limited to javascript, check out link_to_function
. You'll need the id
of the form you want to submit and then you can write some javascript like:
$('the_forms_id').submit(); return false;
Upvotes: 0
Reputation: 103847
Hyperlinks do not have the ability to submit POSTs (not in any browser that I know of, at least). Forms are usually the best way to POST some data.
What you can do, however, is create a form on your page (with the appropriate methods and fields), then create a hyperlink with an onclick
handler that will submit the form. I'm not familiar with RoR to give you an example, but it should be a trivial change to the standard hyperlink-generating function.
(Note that the onclick handler should return false
to prevent the link itself being followed; and ideally the href
of the hyperlink would go to some acceptable page if people have Javascript disabled.)
Upvotes: 0