https://github.com/jfalameda/refinerycms-dynamicfields
This plugin lets the user create models dynamically and attach them to a page type or page ID. Then when editing these pages new fields would be added.
https://github.com/jfalameda/refinerycms-dynamicfields
Last synced: about 2 months ago
JSON representation
This plugin lets the user create models dynamically and attach them to a page type or page ID. Then when editing these pages new fields would be added.
- Host: GitHub
- URL: https://github.com/jfalameda/refinerycms-dynamicfields
- Owner: jfalameda
- Created: 2013-07-12T13:34:45.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T23:50:42.000Z (over 2 years ago)
- Last Synced: 2024-08-03T18:13:06.876Z (11 months ago)
- Language: Ruby
- Size: 120 KB
- Stars: 16
- Watchers: 3
- Forks: 8
- Open Issues: 15
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-refinerycms - refinerycms-dynamicfields - Create models dynamically and attach them to pages (Backoffice extensions)
README
# Custom fields extension for Refinery CMS.
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!
## Installation instructions
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:
```ruby
gem 'refinerycms-dynamicfields', :git => 'https://github.com/jfalameda/refinerycms-dynamicfields.git'
```Run the plugin installation command
```shell
rails generate refinery:dynamicfields
```Run the migrations
```shell
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:
```ruby
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.
## Creating a model and attaching it to a page
1. Create a page and save it.
2. Go to the "Dynamic fields" tab on the administration page
3. Create a new dynamicfield.
4. Select the `page_id` on the criteria section and select the page where the model will be attached on the list
5. Fill the model name and create a few fields, set up a name and an id for them.
6. Save the dynamicform.
7. Now, edit the page we chose to attach the model to and on the "Custom fields" tab the form will be displayed.
8. Enjoy, report bugs and collaborate!## Retrieve the filled fields on the template
In order to retrieve the custom filled information, a helper is provided:
```erb
<% 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:
```erb
<% get_field("another_field_id", 2) %>
```Examples
```erb
Image field
<%= image_fu get_field("hero"), "300x300" %>
Textarea
<%= get_field("hero_text") %>
WYSIWYG field
<%= raw get_field("bigtext") %>
Text field
<%= get_field("facebook_like_url") %>
Resource text (file)
<%= link_to "Download PDF file", get_field("pdf_file").url %>
Another page's field
<%= get_field("other_text", 2) %>
```