Paperclip Error: Model Missing Required Attr_Accessor for 'Avatar_File_Name'

Rails 4: Paperclip Error Post model missing required attr_accessor for 'image_file_name'

Try the following:

def post_params
params.require(:post).permit(:date, :time, :subject, :format, :copy, image: [:image_file_name, :image_file_size, :image_content_type, :image_updated_at])
end

Rails Image Not Showing Up With Paperclip

I think there may be a conflict with your attr_accessor :avatar_file_name in the User model. You're creating your own avatar_file_name attribute and perhaps Paperclip is hitting a conflict when trying to use that itself.

I suggest removing the attr_accessor :avatar_file_name line.

Paperclip and Dropbox Error

I've seen this error before - I originally presumed it was caused by a lack of the paperclip columns in your db. However, according to various sources, this is not the case.

The error seems to be a common issue, which has several fixes:

--

heroku run rake db:migrate

Seems the most common cause of the issue is your heroku db is not updated with the columns required. You've tried running the migrations locally, but not in production

If you're using Herouk toolbelt, you can use heroku run rake db:migrate to trigger the command on your heroku instance

--

strong params

Rails 4 makes a big point of using strong params. Apart from the answer above, you need to also ensure you're using your code properly:

#app/controllers/galeria_controller.rb
def create
@galeria = Galeria.new galeria_params
end

private

def galeria_params
params.require(:galaria).permit(:galeria, :params, :foto)
end

--

paperclip-dropbox

The other thing you may need to consider is the use of the paperclip-dropbox gem. This is an additive to the standard paperclip gem, which facilitates interaction between your app and dropbox

Are you using this gem?

attr_accessor prevent model fields to be saved

By setting your own attr_accessor methods you are overriding Rails logic to fetch those values from the database. I'm guessing you want those values to be saved in the database. If so, just add them as attributes to your model via migrations, and you should be all set.

paperclip + gravatar

I've updated the code to make it easier for you to understand and debug.

Paperclip.interpolates(:gravatar_url) do |attachment, style|
size = nil
# style should be :tiny, :small, or :regular
# size_data is assumed to be "16x16#", "20x20#", or "25x25#", i.e., a string
size_data = attachment.styles[style][:geometry]
if size_data
# get the width of the attachment in pixels
if thumb_size = size_data.match(/\d+/).to_a.first
size = thumb_size.to_i
end
end
# obtain the url from the model
# replace nil with "identicon", "monsterid", or "wavatar" as desired
# personally I would reorder the parameters so that size is first
# and default is second
attachment.instance.gravatar_url(nil, size)
end


Related Topics



Leave a reply



Submit