Form (screen) enter image description here

I attach the error screen [! [Enter image description here] [2]] [2]

I started working with rails yesterday, so I don’t really understand. Here is the model:

class Person < ApplicationRecord validates :name, presence: true validates :age, inclusion: { in: 17..65 }, presence: true, numericality: { only_integer: true } validates :datetime, presence: true has_attached_file :file, styles: { medium: "300x300>", thumb: "100x100>" } end 

Here is the migration:

  class CreatePeople < ActiveRecord::Migration[5.0] def change create_table :people do |t| t.string :name, null:false t.integer :age, null:false t.datetime :datetime, null:false t.attachment :file t.timestamps end end end 

The string that is quarreling

  @person = Person.new(page_params) 

And the procedure (page_params)

  private def page_params params[:person].permit(:name, :age, :datetime, :file) end 

help me please


I tried to pull out the parameter in different ways, I rummaged through the entire Internet, but I can’t decide in any way! Here we take out the parameters:

  private def page_params params[:person].permit(:name, :age, :datetime, :filek => [:tempfile, :original_filename, :content_type, :headers]) end 

Here is the error:

enter image description here

  • With the second error, you can easily figure it out yourself, since this is an obvious typo. I could advise you to post it with a separate question, but as soon as you understand what's the matter, slap your forehead and ask the question to close%) - D-side
  • I sat with the teacher for 2 hours and could not decide) he also does not know. I'll be thinking ... - Samuliak
  • Seriously? Look in your method page_params , then in your migration. Then again in page_params , then again in the migration. (Although in general it is necessary to look not at the migration, but at the base scheme, but these are the details, and there is no scheme in question) - D-side
  • and which one? What is the first question or the second? It was changed many times to achieve the desired goal) - Samuliak
  • The error is in the second question. - D-side

1 answer 1

Answer in README Paperclip , I give a translation:

Safety validation

Thanks to the report of Yegor Khomyakov, we took measures to prevent downloading unexpected data to your server by faking the Content-Type .

NOTE: since version 4.0.0, all attachments must be checked by validation to content_type, file_name, or you must explicitly indicate that they are not. Paperclip will throw an error if you do not.

 class ActiveRecord::Base has_attached_file :avatar # Проверить content-type validates_attachment_content_type :avatar, content_type: /\Aimage/ # Проверить имя файла validates_attachment_file_name :avatar, matches: [/png\z/, /jpe?g\z/] # Отказаться от проверок do_not_validate_attachment_file_type :avatar end 

Because of this, Paperclip is safe by default and will deploy people trying to play with your file system.

... which hints: read the documentation .

  • Help, validation passes (or rather, turned it off), but does not want to create an object! Updated post - Samuliak
  • @Samuliak is a bad idea. Well it is imposed not just like that. I do not observe any updates in the question. - D-side
  • I did not think that you will answer so quickly) already updated. Now I do not do validation until it works at least that way. After all, does not create an object - Samuliak