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?
on 2007-06-13 10:58
on 2007-06-13 12:30
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...@andreas-s.net>
on 2007-06-13 12:35
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 2007-06-13 15:25
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?
on 2007-06-13 15:29
> 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 I 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.
on 2007-06-13 16:35
On 6/13/07, aidanf <firstname.lastname@example.org> wrote: > @site_title = Settings.sitetitle > end That'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 %>
on 2007-06-13 23:14
Awesome, Bob! Thank you so much. Thank you, thank you, thank you. You're the greatest! :)