Reputation: 3189
I have a "create" function which shall redirect to a new view called "view". "view" uses get method, so I need to provide the parameters in the url.
"create" creates a new item 123, and redirects/renders "view" with url /view?id=123
I also want pass on some additional parameters while redirecting to this view, /view?id=123¬e=duplicate
How do I do this?
def create
@i = Book.createNewItem(params[:name])
if @i[:error] == ""
render action: 'view',
else
redirect_to book_home_path
end
end
def view
Book.getItem(params[:id]) #some backend update stuff
@i = Book.find_by_book_num(params[:id])
return @i
end
Upvotes: 1
Views: 4059
Reputation: 1003
You can use
render :action=>'view', :id=>123, :note=>"duplicate"
This will automatically generate 'get' url to view action, like this:
"/view?id=123¬e=duplicate"
Upvotes: 1
Reputation: 10885
You can use this as sipmple
redirect_to "/view?id="+@i+"¬e=duplicate"
Try it...
Upvotes: 0
Reputation: 9167
You can pass additional parameters in a hash, passed to the url helper like this:
redirect_to book_view_path(id: @i.id, note: 'duplicate')
or
redirect_to action: "view", id: 5, note: 'duplicate'
Upvotes: 0