Chris Peters
2010-Jun-25 21:42 UTC
Default Render Action or Help Cleaning Up My View Folder
I have 30 actions which all render basically the same thing, basically their name and a message either indicating success or failure: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><%= "#{action_name} Update Result" %></title> </head> <body> <%= message %> </body> </html> The trouble is, in order to do this I have a layout (partly shown above) and then 30 blank files in my view directory named after the actions they are associated with. I see no reason I have to create 30 blank view files. However, if I don''t create the file then Rails will not render the view because it will error out on not being able to find an associated view file for this action. I have considered adding a render line to the bottom of every action, something like render :file => "layouts/mylayout" but it seems that''s more or less a brute force resolution like making 30 files is a brute force solution. Can I specify a default file to render for every action in a controller? Someone has to know a more elegant, railsy solution to this problem! Thanks for your help, Chris -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Brito
2010-Jun-25 22:47 UTC
Re: Default Render Action or Help Cleaning Up My View Folder
You could use "after_filter :default_render" and then private def default_render render => ... end But probably there is a better sollution here: http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html -- Fernando Brito -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Chris Peters
2010-Jun-25 23:14 UTC
Re: Default Render Action or Help Cleaning Up My View Folder
The after_filter thing I tried before, and it causes a double-render condition. I would then need to go through all the functions and do render :none or something to that effect... Which just goes back to the render at the end of each function problem. Chris On Jun 25, 3:47 pm, Fernando Brito <em...-7WGqr3rU1tXSv/CSzVJHWQC/G2K4zDHf@public.gmane.org> wrote:> You could use "after_filter :default_render" and then > > private > def default_render > render => ... > end > > But probably there is a better sollution here:http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho... > > -- > Fernando Brito-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Brito
2010-Jun-26 23:21 UTC
Re: Re: Default Render Action or Help Cleaning Up My View Folder
Maybe you could try "before_filter" :) But nothing on http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.htmlsolved your problem? :S -- Fernando Brito -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.