As admin, I can create a page so long as it has a title. If I don't fill in the title field I get the uncaught exception below. Rather than the application crashing, I would expect the admin user to receive an error message on screen prompting him to fill in the title field.
NoMethodError in Refinery/admin/pages#create
Showing .bundler/ruby/2.0.0/refinerycms-a03fcf214281/pages/app/views/refinery/admin/pages/_form_advanced_options.html.erb where line #39 raised:
undefined method `map' for nil:NilClass
Extracted source (around line #39):
36: <%= f.label :view_template, t('.view_template') %>
37: <%= refinery_help_tag t('.view_template_help') %>
38: </span>
39: <%= f.select :view_template, @valid_view_templates.map { |t| [t.titleize, t] },
40: template_options(:view_template, @page) %>
41: </div>
42: <% end %>
How can I avoid this error?
Mixed up my Google search a little and found the answer in the Refinery Google Group:
https://groups.google.com/forum/#!msg/refinery-cms/0FfuehWwLgA/kuCgLVlf-nsJ
app/decorators/controllers/refinery/admin/pages_controller_decorator.rb
Refinery::Admin::PagesController.class_eval do
# Solves error when creating pages without title
# See: http://stackoverflow.com/q/19013244/1093087
before_filter :load_valid_templates, :only => [:create, :update, :edit, :new]
end
I now get an error message saying I need to fill in the title as expected.
Thanks to pascal huynh at the groups.google.com link above for the quick fix.