This plugin allows you to create models dynamically and attach them to pages in order to request customizable information and to present it later on the front-end.
This plugin is still in beta and bugs might be found. Please report!
Version 1.1.0 is compatible with Refinery 3.0. For older versions of the CMS use version 1.0.1 of the plugin.
Add the gem to your Gemfile:
gem 'refinerycms-dynamicfields', :git => 'https://github.com/jfalameda/refinerycms-dynamicfields.git'
Run the plugin installation command
rails generate refinery:dynamicfields
Run the migrations
rake db:migrate
Now a new tab with the name "Dynamic fields" will appear on the Refinery backend. There is where you create the models that will be attached to the pages.
IMPORTANT! Remember to activate the page_views
on the configuration file. To do this, go to the file config/initializers/refinery/pages.rb
and comment out the following lines:
config.view_template_whitelist = ["home", "show"]
config.use_view_templates = true
The reason to do this is because the models can be attached to the pages based on an ID or to their templates, so a model would be used on all the pages using a certain view template.
- Create a page and save it.
- Go to the "Dynamic fields" tab on the administration page
- Create a new dynamicfield.
- Select the
page_id
on the criteria section and select the page where the model will be attached on the list - Fill the model name and create a few fields, set up a name and an id for them.
- Save the dynamicform.
- Now, edit the page we chose to attach the model to and on the "Custom fields" tab the form will be displayed.
- Enjoy, report bugs and collaborate!
In order to retrieve the custom filled information, a helper is provided:
<% get_field("field_id") %>
By default the helper method will search for the field in the current page. If you wish to use a field from a specific page, you may also include a page ID:
<% get_field("another_field_id", 2) %>
Examples
<p>
<span>Image field</span>
<%= image_fu get_field("hero"), "300x300" %>
</p>
<p>
<span>Textarea</span>
<%= get_field("hero_text") %>
</p>
<p>
<span>WYSIWYG field</span>
<%= raw get_field("bigtext") %>
</p>
<p>
<span>Text field</span>
<%= get_field("facebook_like_url") %>
</p>
<p>
<span>Resource text (file)</span>
<%= link_to "Download PDF file", get_field("pdf_file").url %>
</p>
<p>
<span>Another page's field</span>
<%= get_field("other_text", 2) %>
</p>