Bob Sanders
2007-Jun-13 08:58 UTC
Displaying "Site Title" from MySQL Throughout Entire Site
I''m an absolute noob, so please excuse my ignorance here :) I''m looking for away to display the site''s title that I''ve entered into a mysql database. Assuming I created the table using this: create table settings ( id int not null auto_increment, yourname varchar(100) not null default , sitetitle varchar(100) not null default , primary key(id) ) engine=InnoDB; How would I fetch that sitetitle to display between the <title></title> tags from the view pages? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
aidanf
2007-Jun-13 10:29 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Site
In your application controller you could do someting like before_filter :get_site_title private def get_site_title end On Jun 13, 9:58 am, Bob Sanders <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m an absolute noob, so please excuse my ignorance here :) > > I''m looking for away to display the site''s title that I''ve entered into > a mysql database. > > Assuming I created the table using this: > > create table settings ( > id int not null auto_increment, > yourname varchar(100) not null default , > sitetitle varchar(100) not null default , > primary key(id) > ) engine=InnoDB; > > How would I fetch that sitetitle to display between the <title></title> > tags from the view pages? > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
aidanf
2007-Jun-13 10:34 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Site
Oops, sorry google groups decided to post while I was still writing (maybe I accidentally hit a key combination to post:(). Anyway... In your application controller you could do something like before_filter :get_site_title private def get_site_title @site_title = Settings.sitetitle end and in your layout <title><%= @site_title %> This means you are adding an extra db query to every page though. Since the site title is not going to change do you really need to store it in the database? Cheers, AF On Jun 13, 11:29 am, aidanf <aid...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In your application controller you could do someting like > > before_filter :get_site_title > > private > def get_site_title > > end > > On Jun 13, 9:58 am, Bob Sanders <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > I''m an absolute noob, so please excuse my ignorance here :) > > > I''m looking for away to display the site''s title that I''ve entered into > > a mysql database. > > > Assuming I created the table using this: > > > create table settings ( > > id int not null auto_increment, > > yourname varchar(100) not null default , > > sitetitle varchar(100) not null default , > > primary key(id) > > ) engine=InnoDB; > > > How would I fetch that sitetitle to display between the <title></title> > > tags from the view pages? > > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders
2007-Jun-13 13:25 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Sit
Hi Aidan! Thanks for your help :-) I followed your instructions, and I''m running into this error: =============================== NameError in ClientController#index uninitialized constant ApplicationController::Settings =============================== I incorporated the: before_filter :get_site_title private def get_site_title @site_title = Settings.sitetitle end into the application.rb controller right underneath the "class ApplicationController < ActionController::Base" Do you know what I might be doing wrong? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders
2007-Jun-13 13:29 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Sit
> This means you are adding an extra db query to every page though. > Since the site title is not going to change do you really need to > store it in the database? > > Cheers, > > AFI forgot to answer your question. My apologies! I''m trying to play around with ROR as much as I can to get a flow of how things work, so I thought about incorporating a feature where the user can change the site''s title. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Jun-13 14:34 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Site
On 6/13/07, aidanf <aidanf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Oops, sorry google groups decided to post while I was still writing > (maybe I accidentally hit a key combination to post:(). Anyway... > > In your application controller you could do something like > > before_filter :get_site_title > > private > def get_site_title > @site_title = Settings.sitetitle > endThat''s not going to work. You need something like: @site_title = Settings.find(:first).sitetitle rescue "Default Title" He might want to just get all the settings: @settings = Settings.find(:first) || Settings.new Then in the view: <%= h @settings.sitetitle %> --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders
2007-Jun-13 21:14 UTC
Re: Displaying "Site Title" from MySQL Throughout Entire Sit
Awesome, Bob! Thank you so much. Thank you, thank you, thank you. You''re the greatest! :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---