I'll try renaming it, but I have used this pattern (and names) on many applications (this test app is an extraction from a working commercial application of mine, although that uses 4.1.8) and I am just trying to stub out multiple file uploads in this exercise.
I just re-built my environment -- re-installed rvm, ruby 2.1.3, bundler, rake, rails 4.2.1, and dropped a couple of gems that looked suspicious -- and started completely over with scaffold again. I am getting the identical problem.
If it's just the name of the model, I will be frankly surprised, because each revision of Rails seems to remove reserved words, not add new ones.
While I do that, here's the actual code -- if you can see anything suspicious, I'd be very grateful.
class Asset < ActiveRecord::Base
belongs_to :project
has_attached_file :blob, :styles => { :large => "800x800", :medium => "400x400>", :small => "200x200>"}
do_not_validate_attachment_file_type :blob
end
class Project < ActiveRecord::Base
has_many :assets
accepts_nested_attributes_for :assets, reject_if: :all_blank, allow_destroy: true
end
Rails.application.routes.draw do
resources :projects
resources :assets
end
The pattern I am trying to solve for is upload multiple assets in the project form (this works perfectly) and edit individual uploaded assets in their own assets/edit form. This latter part does not work.
This is the form that is failing:
<%= form_for(@asset) do |f| %>
<% if @asset.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@asset.errors.count, "error") %> prohibited this asset from being saved:</h2>
<ul>
<% @asset.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :project_id %>
<%= f.text_field :project_id %>
</div>
<div class="field">
<%= f.label :blob %>
<%= f.file_field :blob %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
While this one works just fine:
<%= form_for(@project) do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>
<ul>
<% @project.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<%= f.fields_for :assets do |a| %>
<div class="field">
<%= a.label :blob %>
<%= a.file_field :blob, multiple: true, name: "project[assets_attributes][blob]" %>
</div>
<%- end -%>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Walter