#224
Jul 26, 2010

Controllers in Rails 3

Embedded flash notices, permanent cookies, and the details of respond_with are in this episode.
Download (20.3 MB, 10:49)
alternative download for iPod & Apple TV (18.5 MB, 10:49)

Resources

# config/application.rb
config.filter_parameters += [:password]

# products_controller
redirect_to @product, :notice => "Successfully created product."
redirect_to [:edit, @product]
redirect_to [@category, :edit, @product]

cookies.permanent[:last_product_id] = @product.id

# in class
respond_to :html, :xml

# in action
respond_with(@products)
respond_with(@product, :location => products_url)
respond_with(@product, :responder => MyResponder)
respond_with(@product) do |format|
  format.xml { render :text => "I'm XML!" }
end

RSS Feed for Episode Comments 59 comments

1. doabit Jul 26, 2010 at 02:08

thank you for your video. i am waiting for it every week


2. Branden Silva Jul 26, 2010 at 02:23

respond_with(@awesomeness)

Thanks for the casts Ryan. They are always appreciated.


3. Mickaël Jul 26, 2010 at 02:41

Thank's for your last episode. See you next week for sure ;-)


4. Bagwan Pankaj Jul 26, 2010 at 03:27

Thanks for the awesome episode.


5. docgecko Jul 26, 2010 at 03:40

Brilliant Ryan, thank you very much!

Have you also looked into José Valim's work on Inherited Resourses. I'd love to see you do something on that theme also.

Keep up the top work!!!

D.


6. Emerson Moretto Jul 26, 2010 at 04:38

very very thank you!

Your job is fuckin' good!

I will donate.


7. Geoffroy Jul 26, 2010 at 05:44

Thanks a lot for the screecasts.

It seems a really small error has gone through, in the destroy method of your controller, the respond_with(@product) shall produce an error I think (as the product has just been destroyed).

That aside, you really rock!

Regards


8. Geoffroy Jul 26, 2010 at 05:46

Oops seems I should have watched until the end.
Sorry for this.


9. Renato Jul 26, 2010 at 07:00

respond_with accepts :only and :except options as well.. :)

you can use it for specific actions.. that's the only thing I missed on the video

great work man


10. robs Jul 26, 2010 at 08:16

@Renato, did you mean the respond_to method that takes these options?


11. George Jul 26, 2010 at 14:35

Thanks.


12. Javi Jul 26, 2010 at 14:49

I was wondering what the best way to test these controllers is when testing what happens depending whether the record is valid or not.

My best try so far:

errors = ActiveModel::Errors.new(Post.new)
errors.add_on_blank(:id) Post.any_instance.stubs(:errors).returns(errors) Post.any_instance.stubs(:valid?).returns(false)


13. ones006 Jul 26, 2010 at 19:19

thank you somuch. this is AWESOME. i am wait next video.


14. hakunin Jul 26, 2010 at 21:58

Speaking of respond_with - What do you think about putting it in an after_filter to avoid duplication?


15. 23 Impressions Jul 26, 2010 at 23:11

Impressing .

Cant wait to migrate my present projects to Rails 3.

Eagerly waiting for your next video.


16. Michael Hasenstein Jul 26, 2010 at 23:42

Bryan, for respond_with you removed the HTML specific part - but you left the flash[] in there? So what happens when an XML request is served? The flash is set but it's useless for XML, so it is delivered with the next HTML request, to which it does not belong? Or what am I missing?


17. eryaman halı yıkama Jul 27, 2010 at 01:03

Thanks for the awesome episode.


18. Brian Bartholomew Jul 27, 2010 at 17:23

Awesome!


19. asics shose Jul 27, 2010 at 20:09

Speaking of respond_with - What do you think about putting it in an after_filter to avoid duplication?


20. Jim Jul 27, 2010 at 20:39

cool! these rails3 videos help a lot. Thanks Ryan!


21. RJ Jul 27, 2010 at 23:52

One thing that drives me nuts about the flash is that is sticks around until the next page is loaded.

For example, I like having a single/format for my flash messages and I use them for confirmation messages when CRUD'ing.

However if a user fails to save a record then the page is not redirected but a render event is called instead. This means that the flash is nicely displayed on the current error page but it ALSO sticks around for the next page (Where it isnt correct). I keep having to manually delete the flash whenever an action fails (after the render call) so that it isn't carried on to the next page.


22. buy office 2007 Jul 28, 2010 at 02:42

cool! these rails3 videos help a lot. Thanks Ryan!


23. sunshine Jul 28, 2010 at 20:22

dood post!


24. Terry Schmidt Jul 30, 2010 at 07:36

I had no clue you could do 'redirect_to [:edit, @post]'. I think this is much more concise, especially when you get into nested routes. Great episode :)


25. Terry Schmidt Jul 30, 2010 at 07:47

I had no clue you could do 'redirect_to [:edit, @object]'. This is so much more concise than writing out 'redirect_to edit_object_path(@object)' in my opinion, especially when it comes to nested routes. Great episode :)


26. oakley sunglasses Jul 30, 2010 at 22:09

pecially when it comes to nested routes. Great episode :)


27. pumps Aug 01, 2010 at 19:27

cially when it comes to ne


28. replica mulberry Aug 02, 2010 at 02:37

One thing that drives me nuts about the flash is that is sticks around until the next page is loaded.


29. Steve Aug 03, 2010 at 10:56

@RJ You want to use flash.now instead of flash. Michael Hartl's Rails Tutorial at www.railstutorial.org (free to read online for rails 2.3 and 3, free to download for rails 2.3) talks about it. hope that helps.


30. Roland Aug 04, 2010 at 06:59

Very interesting. Thank you!


31. canli mac izle Aug 05, 2010 at 11:23

great post !!


33. cheap coogi Aug 09, 2010 at 10:18

Here we have popular Polo T-shirt.


34. jordansneaker Aug 10, 2010 at 18:15

A blind man who leans against a wall imagines that it's the boundary of the world.


35. UGG Boots on sale Aug 10, 2010 at 18:37

Gooooooooooooooooooood luck ~~!!


36. N900 Aug 10, 2010 at 19:46

http://www.fashioniphone.com/


37. 90x workout Aug 12, 2010 at 09:24

My friend suggested me to visit your blog. Very well explained. I would like to say that it is very interesting to read your blog.Thanks for the write up! This is really some great stuff here!


38. arno.nyhm Aug 12, 2010 at 15:44

oh ... tooo much spam in the comments :-(


39. replica Isabella Fiore handbags Aug 13, 2010 at 03:06

Embedded flash notices, permanent cookies, and the details of respond_with are in this episode. really? so great.


40. Replica Juicy Couture handbags Aug 13, 2010 at 03:08

thank you very much ......


41. Fake Juicy Couture handbags Aug 13, 2010 at 03:09

thanks for sharing this useful information.


42. herve leger dress Aug 14, 2010 at 10:32

good luck


43. oppo Aug 15, 2010 at 08:36

This was really useful. Thanks Ryan!


44. Rip Blu-ray for Mac Aug 18, 2010 at 01:24

Thanks,it's so good.
suport!


45. Matthijs Groen Aug 18, 2010 at 11:29

When an object has errors, it will redirect to the location if specified. It is not handled in this screencast, but it is not working as it should.

http://gist.github.com/535722


46. medyum hoca Aug 19, 2010 at 06:24

Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming


47. medyum Aug 19, 2010 at 06:25

nice share. thank you


48. wholesale new era caps Aug 20, 2010 at 19:56

The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!


49. converse all star Aug 20, 2010 at 20:35

love converse all star,love yourself.Warm welcome.


50. converse all star Aug 20, 2010 at 20:54

love converse all star,love yourself.High quality low price.It's fit for you.


51. tile floor vacuum Aug 24, 2010 at 10:23

The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!


52. clothes store Aug 24, 2010 at 19:04

David Heinemeier Hansson..thanks


53. PDF to Images Converter Aug 24, 2010 at 22:49

Some times, to a certain need, we have to convert PDF to image for enjoyment.


54. louis vuitton shoes Aug 26, 2010 at 21:04

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets


55. mbt shoes sale Aug 28, 2010 at 10:02

When an object has errors, it will redirect to the location if specified. It is not handled in this screencast, but it is not working as it should.


56. cheap mbt shoes Aug 28, 2010 at 10:12

permanent cookies, and the details of respond_with are in this episode. really? so great.


57. cheap ugg boots sale Aug 28, 2010 at 10:18

thank you very much ......


58. snow boots Aug 30, 2010 at 20:06

the respond_with(@product) shall produce an error I think (as the product has just been destroyed).


59. herve leger dress Aug 30, 2010 at 20:13

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it.


60. louis vuitton sunglasses Sep 01, 2010 at 22:22

Good post, I can’t say that I agree with everything that was said, but very good information overall:)

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player
Give Back to Open Source