Use link to post

Hi, I know I have been a little "long winded" but I really need to use link to do a post/submit. It is in one of the requirements of the project I am doing now.

I have tried using <%= link_to_function 'Next', "$('update_product').submit()" -%>. It works though. But I can't have two of this link_to_functions and redirect each link to a different page. And I had got a feed back saying this link_to_function is a complicated way of doing link. So I tried using <%= link_to 'PREVIOUS', {:controller => 'create_user',                      :action => "save_user" , :method => :post} %>

But this doesn't work as it does not post the values I keyed into the various fields. Instead, it posts an ampty form. I really hope someone can help me with is problem.

Thanks :slight_smile:

The project is not following the conventions of Rails. There are helpers (ala submit_tag) already in place to make this easier in you. Is this a work project or a school project?

The reason why: %= link_to ‘PREVIOUS’,

{:controller => ‘create_user’, :action => “save_user” , :method => :post} is not working is because you’re not passing in the parameters. It’s kind of like trying to go to http://google.com and expecting it to have already looked up what you wanted to search for.

Ryan Bigg wrote:

The project is not following the conventions of Rails. There are helpers (ala submit_tag) already in place to make this easier in you. Is this a work project or a school project?

The reason why: %= link_to 'PREVIOUS', {:controller => 'create_user',                     :action => "save_user" , :method => :post} is not working is because you're not passing in the parameters. It's kind of like trying to go to http://google.com and expecting it to have already looked up what you wanted to search for.

complicated way of doing link. So I tried using <%= link_to 'PREVIOUS',

>

Hi,

Its kink of a school project. So how do I pass the parameters in ?

user splash wrote:

Hi,

Its kink of a school project. So how do I pass the parameters in ?

Hi, This is what I did to try to oass the parameters:

<%= link_to 'PREVIOUS', {:controller => 'create_user',       :action => "save_user", :user => {:username=> 'username', :password=> 'password', :age => 'age'}, :method => :post} %>

I don't know if this is the right way to pass parameters but I got values 0 for each fields that was being entered into my database.Did I do it correctly?

No. Just use a submit_tag, it is MUCH easier. I cannot help you further.

You could set a javascript function on the onClick event of the link which would do a .click on a button with style="visibility:hidden;" I guess... but It's not really an elegant solution.

:url => { :controller => create_user, :action => 'save_user', }, :with => "'address='+encodeURIComponent($F('text_field_name))", :method => :post

from here http://ariejan.net/2007/02/21/ror-link_to_remote-with-a-text_field-value-as-an-argument/