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 of ManagedbController I do:
def edit
@person=Person.find_by(name: params[:name])
end
def update
@person=Person.find_by(name: params[:name])
@person.update_attributes(photo: params[:photo])
end
edit.html.erb
<h2> Add photo here!</h2>
<%= @person.name %>
<%= form_for @person, url: {controller: :managedb,action: :update}, html: {mulitpart: true} do |f| %>
<p><%= f.hidden_field :name %></p>
<p><%= f.file_field :photo %></p>
<p><%= f.submit :submit , class: "btn btn-large btn-success" %></p>
<% end %>
when I visit the edit 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 on the update method:
Mongoid::Errors::DocumentNotFound
Document not found for class Person with attributes {:name=>nil}.
At
@person=Person.find_by(name: params[:name])
Request parameters
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"jpm+Ljk6rvZP9bIUw2gA9BvfZXsnATzsIpEEJMTbuzY=", "person"=>{"name"=>"child", "photo"=>#<ActionDispatch::Http::UploadedFile:0x007ffa20a05330 @original_filename="deepika-padukone-61a.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"person[photo]\"; filename=\"deepika-padukone-61a.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/b2/v1ytdy497fj9md28f7pr9wgm0000gn/T/RackMultipart20130911-3884-daf5yu>>}, "commit"=>"submit", "controller"=>"managedb", "action"=>"update"}
Rack session
What is wrong here? Help! I'm using Mongoid and Rails 3.2.13.