Paperclip: unable to add attachments/photos from update method
I have Person model:
class Person
include Mongoid::Document
include Mongoid::MultiParameterAttributes
include Mongoid::Paperclip
attr_accessible :photo,:name
has_mongoid_attached_file :photo, :styles => {:thumb => "100x100>" },
default_url: "/images/:style/missing.png"
field :photo
field :name
end
And in my update action I do:
def update
@person=Person.find_by(name: params[:name])
@person.update_attributes(photo: params[:photo])
end
update.html.erb
<h2> Add photo here!</h2>
<%= @person.name %>
<%= form_for @person, url: {controller: :managedb,action: :update}, html:
{mulitpart: true} do |f| %>
<p><%= f.file_field :photo %></p>
<p><%= f.submit :submit , class: "btn btn-large btn-success" %></p>
<% end %>
when I visit the update page I'm getting the name of the person from
@person.name which means that the @person variable is NOT NIL
But when I select a image and click on submit I get this error:
Mongoid::Errors::DocumentNotFound
Document not found for class Person with attributes {:name=>nil}.
At
@person=Person.find_by(name: params[:name])
What is wrong here? Help! I'm using Mongoid and Rails 3.2.13.
No comments:
Post a Comment