开发者

How to I change the button into hypertext in RoR

Here is the code for generate button, but I want it in a hyper text, how to modify this?

开发者_Python百科
<% 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?


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.


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.)


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜