Hi everyone,
I would like to set some site-wide (global) values across my application
layout.
All these global values are stored in my Settings table.
So in my Application controller I have something like this:
#Application Controller:
before_filter :grab_settings
def grab_settings
@set = Setting.first
end
#Application Layout view
<div>
<p><%= @set.company_name %></p>
</div>
All of this works fine, though. But if the "company_name" field is
empty, than you wouldn't see anything.
So in that case I would like to default to a other value.
I fixed that by doing the following:
<div>
<% if @set.company_name.empty? %>
<p>My company</p>
<% else %>
<p><%= @set.company_name %></p>
<% end %>
</div>
However isn't there a better way to do this? Initially I thought I could
do something more elegant like this:
<%= @set.company_name || "My company" %> but ofcourse, that won't work.
So basically I'm looking for a more polished/clean/better approach.
Any help is appreciated.
Thanks in advance!
--
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@googlegroups.com.
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.
No comments:
Post a Comment