Reputation: 469
I have an issue retrieving my file upload information. I am just starting to learn Rails.
I am using ruby 2.0.0p0 And Rails 4.0.0.beta1
Here is my form:
<%= form_for(@person, :html => { :multipart => true }) do |f| %>
<div class="field">
<%= f.label :photo %><br />
<%= f.file_field :photo %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
And in my person.rb model:
def photo=(file_data)
logger.debug("PHOTO")
logger.debug(file_data)
logger.debug("END OUTPUT PHOTO")
unless file_data.blank?
@file_data = file_data
self.extension = file_data.original_filename.split('.').last.downcase
end
end
I can see in my console that nothing happens (no "PHOTO" output), the photo method is never called. Why is that?
When I looked in the console I also saw this line that got me worried:
Unpermitted parameters: photo
What does that mean?
Upvotes: 0
Views: 823
Reputation: 124449
In your controller, where you're dealing with params
, you need to use .permit
to list the attributes the form is allowed to post:
@person = Person.new(params.require(:person).permit(:photo))
Alternatively, if you used Rails' scaffolding generator, you might instead have a person_params
method where you would need to add the :photo
attribute:
def person_params
params.require(:person).permit(:photo, :name, etc...)
end
Upvotes: 3