librelist archives

« back to archive

Mass-Assignment Error - Polymorphic Paperclip Image

Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-21 @ 14:47
Hey Everyone, I'm running into a problem trying to use a polymorphic
paperclip image object when used as a nested object with simple form. I'm
not sure where I went wrong:

*Models*
*
*
*Image:*
class Image < ActiveRecord::Base
  attr_accessible :image_name
  belongs_to :imageable, :polymorphic => true
  validates :image_name, presence: true

  has_attached_file :image_name,
   :storage => :s3, :s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
   :path => "/images/:filename"
end

*Startup:*
class Startup < ActiveRecord::Base
  attr_accessible :screenshot, :screenshots, :screenshots_attributes,
: screenshot_attributes,

  has_many :screenshots, :class_name => "Image", :as => :imageable,
:dependent => :destroy
  accepts_nested_attributes_for :screenshots

end

*Startup _form.html.erb*
<%= simple_form_for(@startup) do |f| %>
  <% if @startup.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@startup.errors.count, "error") %> prohibited this
startup from being saved:</h2>

      <ul>
      <% @topic.edicas
      nocqe
      rrors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>

    </div>
  <% end %>

  <%= f.simple_fields_for :screenshots do |s| %>
    <%= s.file_field :screenshot %>
    asdf
  <% end %>


  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-21 @ 14:55
Sorry, here is the Error:

ActiveModel::MassAssignmentSecurity::Error in StartupsController#create

Can't mass-assign protected attributes: screenshot


On Sat, Jul 21, 2012 at 8:47 AM, Nelson Wittwer <nelsonwittwer@gmail.com>wrote:

> Hey Everyone, I'm running into a problem trying to use a polymorphic
> paperclip image object when used as a nested object with simple form. I'm
> not sure where I went wrong:
>
> *Models*
> *
> *
> *Image:*
> class Image < ActiveRecord::Base
>   attr_accessible :image_name
>   belongs_to :imageable, :polymorphic => true
>    validates :image_name, presence: true
>
>   has_attached_file :image_name,
>    :storage => :s3, :s3_credentials =>
> "#{Rails.root}/config/amazon_s3.yml",
>    :path => "/images/:filename"
> end
>
> *Startup:*
> class Startup < ActiveRecord::Base
>   attr_accessible :screenshot, :screenshots, :screenshots_attributes,
> : screenshot_attributes,
>
>   has_many :screenshots, :class_name => "Image", :as => :imageable,
> :dependent => :destroy
>   accepts_nested_attributes_for :screenshots
>
> end
>
> *Startup _form.html.erb*
> <%= simple_form_for(@startup) do |f| %>
>   <% if @startup.errors.any? %>
>     <div id="error_explanation">
>       <h2><%= pluralize(@startup.errors.count, "error") %> prohibited this
> startup from being saved:</h2>
>
>       <ul>
>       <% @topic.edicas
>       nocqe
>       rrors.full_messages.each do |msg| %>
>         <li><%= msg %></li>
>       <% end %>
>       </ul>
>
>     </div>
>   <% end %>
>
>   <%= f.simple_fields_for :screenshots do |s| %>
>     <%= s.file_field :screenshot %>
>     asdf
>   <% end %>
>
>
>   <div class="actions">
>     <%= f.submit %>
>   </div>
> <% end %>
>
>

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Robert Karlsson
Date:
2012-07-21 @ 15:08
Have you restarted the console since creating the model?  Also you have a
comma at the end of the line which may be messing with you

attr_accessible :screenshot, :screenshots, :screenshots_attributes,
: screenshot_attributes, <---------


On Sat, Jul 21, 2012 at 8:55 AM, Nelson Wittwer <nelsonwittwer@gmail.com>wrote:

> Sorry, here is the Error:
>
> ActiveModel::MassAssignmentSecurity::Error in StartupsController#create
>
> Can't mass-assign protected attributes: screenshot
>
>
> On Sat, Jul 21, 2012 at 8:47 AM, Nelson Wittwer <nelsonwittwer@gmail.com>wrote:
>
>> Hey Everyone, I'm running into a problem trying to use a polymorphic
>> paperclip image object when used as a nested object with simple form. I'm
>> not sure where I went wrong:
>>
>> *Models*
>> *
>> *
>> *Image:*
>> class Image < ActiveRecord::Base
>>   attr_accessible :image_name
>>   belongs_to :imageable, :polymorphic => true
>>    validates :image_name, presence: true
>>
>>   has_attached_file :image_name,
>>    :storage => :s3, :s3_credentials =>
>> "#{Rails.root}/config/amazon_s3.yml",
>>    :path => "/images/:filename"
>> end
>>
>> *Startup:*
>> class Startup < ActiveRecord::Base
>>   attr_accessible :screenshot, :screenshots, :screenshots_attributes,
>> : screenshot_attributes,
>>
>>   has_many :screenshots, :class_name => "Image", :as => :imageable,
>> :dependent => :destroy
>>   accepts_nested_attributes_for :screenshots
>>
>> end
>>
>> *Startup _form.html.erb*
>> <%= simple_form_for(@startup) do |f| %>
>>   <% if @startup.errors.any? %>
>>     <div id="error_explanation">
>>       <h2><%= pluralize(@startup.errors.count, "error") %> prohibited
>> this startup from being saved:</h2>
>>
>>       <ul>
>>       <% @topic.edicas
>>       nocqe
>>       rrors.full_messages.each do |msg| %>
>>         <li><%= msg %></li>
>>       <% end %>
>>       </ul>
>>
>>     </div>
>>   <% end %>
>>
>>   <%= f.simple_fields_for :screenshots do |s| %>
>>     <%= s.file_field :screenshot %>
>>     asdf
>>   <% end %>
>>
>>
>>   <div class="actions">
>>     <%= f.submit %>
>>   </div>
>> <% end %>
>>
>>
>

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-21 @ 16:26
I just restarted the console and server, still same problem. Also, I
deleted the comma. Any other ideas?

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-21 @ 16:56
what is the value of the params object when this fails?


On Jul 21, 2012, at 10:26 AM, Nelson Wittwer wrote:

> I just restarted the console and server, still same problem. Also, I 
deleted the comma. Any other ideas?

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-21 @ 17:02
Request

*Parameters*:

{"utf8"=>"✓",
 "authenticity_token"=>"RLtTTVGphEXVPqnNbQu5rL+i6laMoZyi2FW1I3rbNnA=",
 "startup"=>{"name"=>"asdf",
 "url"=>"asdf",
 "twitter"=>"",
 "crunchbase"=>"",
 "description"=>"asdf",
 
"screenshots_attributes"=>{"0"=>{"screenshot"=>#<ActionDispatch::Http::UploadedFile:0x007f8bf47163f8
@original_filename="logo-small.png",
 @content_type="image/png",
 @headers="Content-Disposition: form-data;
name=\"startup[screenshots_attributes][0][screenshot]\";
filename=\"logo-small.png\"\r\nContent-Type: image/png\r\n",
 
@tempfile=#<File:/var/folders/p3/h67sybqd0zjfmy6wvhm924740000gn/T/RackMultipart20120721-41944-y5ir4v>>}},
 "tag_ids"=>[""]},
 "commit"=>"Create Startup"}

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Robert Karlsson
Date:
2012-07-21 @ 17:04
try:  <%= f.simple_fields_for  @screenshots do |s| %>

On Sat, Jul 21, 2012 at 10:26 AM, Nelson Wittwer <nelsonwittwer@gmail.com>wrote:

> I just restarted the console and server, still same problem. Also, I
> deleted the comma. Any other ideas?

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-21 @ 17:05
This is a flyer and may have NO bearing at all  but maybe it does so I'll 
throw it out there.

I notice that you have fields called screen_shot and screen_shots (plural)


you also have a relationship established "has_many :screenshots" in the Startup.

I think this implicitly creates a getter of some sort called screenshot 
which may be conflicting with your variable name.  I have not done any 
tests on this and it's just off the top of my head but maybe it will 
help.. I may be full of it.

hope this helps.

Max


On Jul 21, 2012, at 8:55 AM, Nelson Wittwer wrote:

> ActiveModel::MassAssignmentSecurity::Error in StartupsController#create
> 
> 

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-21 @ 17:46
Max - I kind of included a plural version and a singular version just to
make sure my bases were covered. I've played around with removing and
keeping some, no luck.

Robert - I tried changing it to an instance variable and it started
breaking other things. I don't think it has to do setting screenshots as an
instance variable since the form/paperclip image upload works fine in it's
current state. I could be wrong though.

Re: [getarailsjob] Re: Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-21 @ 17:50
wish i could help. no ideas.  all my googling indicates the need for the 
attr_accessible which you already have in there…

is the code in a github repo?  Maybe pulling it down and having my hands 
on it would help.  i have never played with paperclip so that would be fun
too :)


good luck

Max


On Jul 21, 2012, at 11:46 AM, Nelson Wittwer wrote:

> Max - I kind of included a plural version and a singular version just to
make sure my bases were covered. I've played around with removing and 
keeping some, no luck.
> 
> Robert - I tried changing it to an instance variable and it started 
breaking other things. I don't think it has to do setting screenshots as 
an instance variable since the form/paperclip image upload works fine in 
it's current state. I could be wrong though.

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-21 @ 17:51
maybe this would help?


http://stackoverflow.com/questions/10239285/rails-3-1-nested-forms-issue-cant-mass-assign-protected-attributes



On Jul 21, 2012, at 11:50 AM, Allen Maxwell wrote:

> wish i could help. no ideas.  all my googling indicates the need for the
attr_accessible which you already have in there…
> 
> is the code in a github repo?  Maybe pulling it down and having my hands
on it would help.  i have never played with paperclip so that would be fun
too :)
> 
> 
> good luck
> 
> Max
> 
> 
> On Jul 21, 2012, at 11:46 AM, Nelson Wittwer wrote:
> 
>> Max - I kind of included a plural version and a singular version just 
to make sure my bases were covered. I've played around with removing and 
keeping some, no luck.
>> 
>> Robert - I tried changing it to an instance variable and it started 
breaking other things. I don't think it has to do setting screenshots as 
an instance variable since the form/paperclip image upload works fine in 
it's current state. I could be wrong though.
> 

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
David Richards
Date:
2012-07-22 @ 05:17
Sorry I missed all this.  I was at a friends helping with sprinklers all
day.  I'll be around tomorrow if this is still unresolved.

On Sat, Jul 21, 2012 at 11:51 AM, Allen Maxwell <aamax@xmission.com> wrote:

> maybe this would help?
>
>
> 
http://stackoverflow.com/questions/10239285/rails-3-1-nested-forms-issue-cant-mass-assign-protected-attributes
>
>
>
> On Jul 21, 2012, at 11:50 AM, Allen Maxwell wrote:
>
> wish i could help. no ideas.  all my googling indicates the need for the
> attr_accessible which you already have in there…
>
> is the code in a github repo?  Maybe pulling it down and having my hands
> on it would help.  i have never played with paperclip so that would be fun
> too :)
>
>
> good luck
>
> Max
>
>
> On Jul 21, 2012, at 11:46 AM, Nelson Wittwer wrote:
>
> Max - I kind of included a plural version and a singular version just to
> make sure my bases were covered. I've played around with removing and
> keeping some, no luck.
>
>
> Robert - I tried changing it to an instance variable and it started
> breaking other things. I don't think it has to do setting screenshots as an
> instance variable since the form/paperclip image upload works fine in it's
> current state. I could be wrong though.
>
>
>
>

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-24 @ 13:20
So I've tried a few things over the past few days, but still am running
into the same error as before and can't find what happened.. The most
up-to-date code is on github if one of you would be so kind as to take a
look.

github.com/nelsonwittwer/disrupt

If you click on startups on the menu bar and try to add a new startup with
an image you'll see the error: Can't mass-assign protected attributes:
screenshot

Thank you so much for your help!

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-24 @ 14:14
I have to install imagemagick and since i'm on a Mac it's apparently going
to take a little while to do it.  I'll try to do it tonight.


On Jul 24, 2012, at 7:20 AM, Nelson Wittwer wrote:

> So I've tried a few things over the past few days, but still am running 
into the same error as before and can't find what happened.. The most 
up-to-date code is on github if one of you would be so kind as to take a 
look. 
> 
> github.com/nelsonwittwer/disrupt
> 
> If you click on startups on the menu bar and try to add a new startup 
with an image you'll see the error: Can't mass-assign protected 
attributes: screenshot
> 
> Thank you so much for your help!

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-24 @ 14:32
Using homebrew made the installation process less painful, I'd recommend
that route.

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
David Richards
Date:
2012-07-24 @ 14:42
Starting the install process now...

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
David Richards
Date:
2012-07-24 @ 16:41
So, I've got a page full of notes and suggestions.  I've got family things
to do today, but if you can grab me on Google, I can walk you through what
I've done so far and we can keep going.

Cheers,

David



On Tue, Jul 24, 2012 at 8:42 AM, David Richards <
davidlamontrichards@gmail.com> wrote:

> Starting the install process now...
>

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Allen Maxwell
Date:
2012-07-24 @ 13:57
Hi Nelson, 

I downloaded your project and attempted to run bundler and got this:

Installing rmagick (2.13.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb 
checking for Ruby version >= 1.8.5... yes
extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
checking for /usr/bin/gcc-4.2... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/bin:/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@global/bin:/Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/bin:/Users/allenmaxwell/.rvm/bin:/Library/PostgreSQL/9.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/bin/ruby


Gem files will remain installed in 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/gems/rmagick-2.13.1 
for inspection.
Results logged to 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/gems/rmagick-2.13.1/ext/RMagick/gem_make.out
An error occured while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.


looks like some challenges with RMagick.   I'll work on this as i have 
some time but it won't be until tonight.  

Max

On Jul 24, 2012, at 7:20 AM, Nelson Wittwer wrote:

> So I've tried a few things over the past few days, but still am running 
into the same error as before and can't find what happened.. The most 
up-to-date code is on github if one of you would be so kind as to take a 
look. 
> 
> github.com/nelsonwittwer/disrupt
> 
> If you click on startups on the menu bar and try to add a new startup 
with an image you'll see the error: Can't mass-assign protected 
attributes: screenshot
> 
> Thank you so much for your help!

Re: [getarailsjob] Mass-Assignment Error - Polymorphic Paperclip Image

From:
Nelson Wittwer
Date:
2012-07-24 @ 14:16
Thanks for your help Max. If you go to the paper clip page on github they 
have some instructions on image magick. I really appreciate your help. 



On Jul 24, 2012, at 7:57 AM, Allen Maxwell <aamax@xmission.com> wrote:

> Hi Nelson, 
> 
> I downloaded your project and attempted to run bundler and got this:
> 
> Installing rmagick (2.13.1) with native extensions 
> Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native 
extension.
> 
>         /Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb 
> checking for Ruby version >= 1.8.5... yes
> extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
> checking for /usr/bin/gcc-4.2... yes
> checking for Magick-config... no
> Can't install RMagick 2.13.1. Can't find Magick-config in 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/bin:/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@global/bin:/Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/b

in:/Users/allenmaxwell/.rvm/bin:/Library/PostgreSQL/9.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin
> 
> *** extconf.rb failed ***
> Could not create Makefile due to some reason, probably lack of
> necessary libraries and/or headers.  Check the mkmf.log file for more
> details.  You may need configuration options.
> 
> Provided configuration options:
> 	--with-opt-dir
> 	--with-opt-include
> 	--without-opt-include=${opt-dir}/include
> 	--with-opt-lib
> 	--without-opt-lib=${opt-dir}/lib
> 	--with-make-prog
> 	--without-make-prog
> 	--srcdir=.
> 	--curdir
> 	--ruby=/Users/allenmaxwell/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
> 
> 
> Gem files will remain installed in 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/gems/rmagick-2.13.1 
for inspection.
> Results logged to 
/Users/allenmaxwell/.rvm/gems/ruby-1.9.3-p125@steve/gems/rmagick-2.13.1/ext/RMagick/gem_make.out
> An error occured while installing rmagick (2.13.1), and Bundler cannot continue.
> Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.
> 
> 
> looks like some challenges with RMagick.   I'll work on this as i have 
some time but it won't be until tonight. 
> 
> Max
> 
> On Jul 24, 2012, at 7:20 AM, Nelson Wittwer wrote:
> 
>> So I've tried a few things over the past few days, but still am running
into the same error as before and can't find what happened.. The most 
up-to-date code is on github if one of you would be so kind as to take a 
look. 
>> 
>> github.com/nelsonwittwer/disrupt
>> 
>> If you click on startups on the menu bar and try to add a new startup 
with an image you'll see the error: Can't mass-assign protected 
attributes: screenshot
>> 
>> Thank you so much for your help!
>