Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Rails Routes and Resources Routes to Create Actions Controller Action to Create Pages

PoJung Chen
PoJung Chen
5,856 Points

What does it mean by passing an instance object into redirect_to method?

There is no url information in the @page instance object, why I can get url path by passing this parameter into redirect_to method ?

2 Answers

Wout Ceulemans
Wout Ceulemans
17,603 Points

I think I found someone else who had a similar question here. I don't think I can answer the question better than Nishant did (which you can find here), however I'll try to explain briefly.

The @page instance variable is a specific record with an id. Because of this, rails is smart enough to figure out you would probably want to show that particular page (identified with the id). Thus, the show method is used as a template.

For more information you could always check out the documentation: http://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to

PoJung Chen
PoJung Chen
5,856 Points

Thanks for your explanation and giving me the link on stackoverflow. It's really helpful!!

So basically it #shows (Displays) information about the record object, using the options record objects, that's it. I'm assumign it just parses the id calls url_for on it and then issues a route to a controller action that matched the GET and the option(record) locally. I'm pretty sure it doesn't tell the browser to issue the show route, right?