After create redirect to custom action

70 views
Skip to first unread message

maddin

unread,
Jun 22, 2009, 11:56:57 AM6/22/09
to make_resourceful
Hi there!

First of all, I'm very new to ruby on rails and the make_resourceful
plugin. I want to extend an existing controller. The idea is that a
user creates a new object and then gets redirected to another page
where he can choose several options. At first I tried this inside of
make_resourceful do:

after :create
redirect_to :action => 'choose_design', :id => current_object.id

But then I got a routing error. My second idea is to overwrite the
create action, but I don't think this is in the concept of DRY.

Can anybody help me?

Thanks!

Robert Fischer

unread,
Jun 22, 2009, 12:09:07 PM6/22/09
to make_res...@googlegroups.com
Check the source -- you can probably hijack the appropriate method call to implement the redirect as
you'd like, without having to hijack the entire create action.

make_resourceful is extremely modular, which is part of the reason I like it so much.

~~ Robert.

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "make_resourceful" group.
> To post to this group, send email to make_res...@googlegroups.com
> To unsubscribe from this group, send email to make_resourcef...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/make_resourceful?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>

--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

signature.asc

Hampton

unread,
Jun 22, 2009, 12:11:45 PM6/22/09
to make_res...@googlegroups.com
Well, your code should be

response_for :create do

  redirect_to :action => 'choose_design', :id => current_object.id
end

That makes sure that it only calls "render" (really, redirect_to is just a call to render)
once... by overriding the original response_for.

But, you are also going to have a routing error, because if this is a REST-based
controller, you can't create arbitrary actions. You have to manually add them to the
router. Look up :collection and :member methods in the routing file.

-hampton.

maddin

unread,
Jun 22, 2009, 12:20:40 PM6/22/09
to make_resourceful
Hi!

Yes, it is a REST-based controller. Thanks for the tip with routes.rb
I just added the following to the controller:

response_for :create do
redirect_to :action => 'choose_design', :id => current_object.id
end

and then added in routes.rb to :member => {... :choose_design
=> :get } and now after creating a new object 'choose_design' is
called.

Thanks a lot!

Martin

Hampton

unread,
Jun 22, 2009, 12:35:15 PM6/22/09
to make_res...@googlegroups.com
No problem at all.

And Kudos as a second-developer for not simply re-writing everything when
you got stuck and instead asked a very well-put question.

Whoever the original developer was should be very happy to know that
someone like you is on the job. ;)

-hampton.
Reply all
Reply to author
Forward
0 new messages