I have been looking for a way to use/override the layout.rb render_with_layout method to add the ability to render from a string instead of a file on the file system. I would like to be able to have the layouts stored in the db and let rails use that as the layout for a site. So far, I haven''t been able to figure out how the method even works. I am still a ruby nuby so some of the syntax I don''t quite get. For instance this line: if layout ||= active_layout and action_has_layout? I am not quite sure what the ||= does. I know, || is or and = is assign but together what does it do? Then I notice the call to render_without_layout(layout, status) which is a non-existant method, however looking at the - base.class_eval do creates an alias to :render for the missing method. Right below that alias is another alias to the method that calls it - alias_method :render, :render_with_layout so I am lost at this point. If anyone could point me in the right direction I would appreciate it. Scott http://spurton.blogspot.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I have been looking for a way to use/override the layout.rb render_with_layout method to add the ability to render from a string instead of a file on the file system. I would like to be able to have the layouts stored in the db and let rails use that as the layout for a site. So far, I haven''t been able to figure out how the method even works. I am still a ruby nuby so some of the syntax I don''t quite get. For instance this line: if layout ||= active_layout and action_has_layout? I am not quite sure what the ||= does. I know, || is or and = is assign but together what does it do? Then I notice the call to render_without_layout(layout, status) which is a non-existant method, however looking at the - base.class_eval do creates an alias to :render for the missing method. Right below that alias is another alias to the method that calls it - alias_method :render, :render_with_layout so I am lost at this point. If anyone could point me in the right direction I would appreciate it. Scott http://spurton.blogspot.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Apr 19, 2005, at 4:17 PM, Scott Burton wrote:> I am still a ruby nuby so some of the syntax I don''t quite get. For > instance this line: > if layout ||= active_layout and action_has_layout? > I am not quite sure what the ||= does.See the first entry in http://www.rubygarden.org/ruby?RubyIdioms (An answer to half your questions is better than none :) -- (-, /\ \/ / /\/
Wow, thanks that helped. I like this one: Using idioms does not always lead to the most readable code, but they can provide convenient shortcuts in many situations. Very true in both cases :) Scott http://spurton.blogspot.com -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gavin Kistner Sent: Wednesday, April 20, 2005 6:42 AM To: sburton-w+tqpK57T0M7uZOk4t9J8dBPR1lH4CV8@public.gmane.org; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] render_with_layout hook On Apr 19, 2005, at 4:17 PM, Scott Burton wrote:> I am still a ruby nuby so some of the syntax I don''t quite get. For > instance this line: > if layout ||= active_layout and action_has_layout? > I am not quite sure what the ||= does.See the first entry in http://www.rubygarden.org/ruby?RubyIdioms (An answer to half your questions is better than none :) -- (-, /\ \/ / /\/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 20/04/2005, at 11:42 PM, Gavin Kistner wrote:> On Apr 19, 2005, at 4:17 PM, Scott Burton wrote: >> I am still a ruby nuby so some of the syntax I don''t quite get. For >> instance this line: >> if layout ||= active_layout and action_has_layout? >> I am not quite sure what the ||= does. > > See the first entry in http://www.rubygarden.org/ruby?RubyIdiomsAnd for the most entertaining and interesting introduction to Ruby: http://poignantguide.net/ruby/ highly recommended. - tim lucas
Tim Lucas <t.lucas-l/qNJNvq70OzaBltdDZI6w@public.gmane.org> writes:> On 20/04/2005, at 11:42 PM, Gavin Kistner wrote: >> On Apr 19, 2005, at 4:17 PM, Scott Burton wrote: >> >>> I am still a ruby nuby so some of the syntax I don''t quite get. For >>> instance this line: >>> >>> if layout ||= active_layout and action_has_layout? >>> >>> I am not quite sure what the ||= does. >> >> See the first entry in http://www.rubygarden.org/ruby?RubyIdioms > > And for the most entertaining and interesting introduction to Ruby: > http://poignantguide.net/ruby/ > > highly recommended.I haven''t read the poignant guide to ruby recently, but I remember it being a very entertaining read. You might read it again if you haven''t. There''s a different perspective reading now and using ruby to just reading it as an entertaining guide. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
Hah, that is funny I was just reading the poignantguide and decided to check this thread. Too bad David Hansson doesn''t read this thred, maybe he could give some insight on how I could tie into the layout rendering. Scott http://spurton.blogspot.com -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Tim Lucas Sent: Wednesday, April 20, 2005 8:25 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] render_with_layout hook On 20/04/2005, at 11:42 PM, Gavin Kistner wrote:> On Apr 19, 2005, at 4:17 PM, Scott Burton wrote: >> I am still a ruby nuby so some of the syntax I don''t quite get. For >> instance this line: >> if layout ||= active_layout and action_has_layout? >> I am not quite sure what the ||= does. > > See the first entry in http://www.rubygarden.org/ruby?RubyIdiomsAnd for the most entertaining and interesting introduction to Ruby: http://poignantguide.net/ruby/ highly recommended. - tim lucas _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 20/04/2005, at 8:17 AM, Scott Burton wrote:> I have been looking for a way to use/override the layout.rb > render_with_layout method to add the ability to render from a string > instead of a file on the file system. I would like to be able to have > the layouts stored in the db and let rails use that as the layout for > a site. So far, I haven''t been able to figure out how the method even > works. > > I am still a ruby nuby so some of the syntax I don''t quite get. For > instance this line: if layout ||= active_layout and action_has_layout? > I am not quite sure what the ||= does. I know, || is or and = is > assign but together what does it do? Then I notice the call to > render_without_layout(layout, status) which is a non-existant method, > however looking at the - base.class_eval do creates an alias to > :render for the missing method. Right below that alias is another > alias to the method that calls it - alias_method :render, > :render_with_layout so I am lost at this point. If anyone could point > me in the right direction I would appreciate it.My guess would be changing render_without_layout to render_string, passing in the layout string from the db. It would be nice if DHH could add a hook to supply the layout template string yourself, as the above is a very dirty hack. - tim lucas
I added a ticket for it so maybe it will happen. Scott http://spurton.blogspot.com -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Tim Lucas Sent: Wednesday, April 20, 2005 5:23 PM To: sburton-w+tqpK57T0M7uZOk4t9J8dBPR1lH4CV8@public.gmane.org; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] render_with_layout hook On 20/04/2005, at 8:17 AM, Scott Burton wrote:> I have been looking for a way to use/override the layout.rb > render_with_layout method to add the ability to render from a string > instead of a file on the file system. I would like to be able to have > the layouts stored in the db and let rails use that as the layout for > a site. So far, I haven''t been able to figure out how the method even > works. > > I am still a ruby nuby so some of the syntax I don''t quite get. For > instance this line: if layout ||= active_layout and action_has_layout? > I am not quite sure what the ||= does. I know, || is or and = is > assign but together what does it do? Then I notice the call to > render_without_layout(layout, status) which is a non-existant method, > however looking at the - base.class_eval do creates an alias to > :render for the missing method. Right below that alias is another > alias to the method that calls it - alias_method :render, > :render_with_layout so I am lost at this point. If anyone could point > me in the right direction I would appreciate it.My guess would be changing render_without_layout to render_string, passing in the layout string from the db. It would be nice if DHH could add a hook to supply the layout template string yourself, as the above is a very dirty hack. - tim lucas _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails