Is it possible to display a static url for a show action (for example something like /coming_soon and not /invitations/:id) ?
Why?
I want that after a create action the new view rendered (/coming_soon) displays the specific id of the created invi开发者_如何学Pythontation. Can I use a get request to do this? Do I have to use a global var in my create action?
As info, here is my invitation controller:
def show
@invitation = Invitation.find(params[:id])
end
def new
@invitation = Invitation.new
end
def create
@invitation = Invitation.new(params[:invitation])
if @invitation.save
redirect_to @invitation
else
render :action => 'new'
end
end
Thanks a lot for this!
If I understand you correctly you want to redirect the user to the "show" action of the invitations controller after a create action. In the view of the show action (or name it coming_soon) you want to have access to the ID of the invitation which is just created in the create action.
To achieve this the easiest might be to store the ID in a cookie or session, read it out in the show action and then remove it. When using sessions you might get problems with horizontal scaling if you need this later on.
if i understand you correctly then in your routes.rb you are looking for
match '/coming_soon', :to => 'controller_name#show'
also for more routing help check out this link
精彩评论