Extracted from Refinery CMS
Ruby
Pull request Compare This branch is 101 commits behind refinery:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
db/migrate
lib
script
spec
tasks
.gitignore
.rspec
.travis.yml
Gemfile
Rakefile
license.md
readme.md
refinerycms-settings.gemspec

readme.md

Settings

Refinery Settings

About

Refinery Settings was extracted from Refinery CMS just before 2.0.0 was released and now it can be used separately.

How do I Make my Own Settings?

In view

Settings can be really useful, especially when you have custom display logic or new plugins that need to behave in different ways.

To best explain how settings, work let's use an example. Say you have a client who has a display in a local trade show every year and 2 months before the trade show, they want to display a little banner in the header of all pages.

But once the trade show is finished, the client needs to be able to hide it again until next year. This is what your application.html.erb file might look like:

...
<div id='header'>
  <h1>My Company</h1>

  <% if ::Refinery::Setting.find_or_set(:show_trade_show_banner, false) %>
    <%= image_tag ('trade-show-banner.jpg') %>
  <% end %>
</div>
...

The following will automatically create a new Refinery setting called "show_trade_show_banner" and set its default it to false. If that setting already exists, it just reads in what the current value is.

So as you can see, this is quite clever because you can quickly define new settings and their defaults right from the view as you need them.

This setting would then show up in the backend in the 'Settings' area where the client could change the value as their trade show approaches. Easy as pie!

In Controller

limit = Refinery::Setting.find_or_set(:list_limit, 20)