In a view I have links with the following format:
<%= link_to "User", move_on_path(organization: organization, url: edit_profile_path(@user)) %>
This uses a controller method that first calls on a method that sets a session
value and then moves on to the specified url
:
def move_on
@organization = Organization.find_by(params[:organization])
set_session(@organization)
redirect_to params[:url]
end
This works but now I have an url
for which the method is post
rather then get
. I don't know the syntax for the link when it's a post
method. So I have the syntax below but need it to post
to edit_profile_path
. How can I specify this in the syntax below (or is there no way around changing def move_on
for this)?
<%= link_to "User", move_on_path(organization: organization, url: edit_profile_path(@user)) %>
Update: Using @Chuck Callebs answer below I've changed the controller method to:
def move_on
@organization = Organization.find_by(params[:organization])
set_session(@organization)
if params[:_url] == 'users#edit'
post_to params[:url]
else
redirect_to params[:url]
end
Would this be correct? I made up post_to
to explain what I would like it to do, but what would be the correct code as to make it post to the url
?
I don't think it's a duplicate post since it's more about looking for the solution in this use case then about whether a post
request is possible.