Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:32:47+00:00 2026-05-28T03:32:47+00:00

Using rails 3.1.1, Ruby 1.9.2, Gems: gem ‘haml’, gem ‘simple_form’, gem ‘aws-sdk’, gem ‘paperclip’,

  • 0

Using rails 3.1.1, Ruby 1.9.2,
Gems: gem ‘haml’, gem ‘simple_form’, gem ‘aws-sdk’,
gem ‘paperclip’, :git => “git://github.com/thoughtbot/paperclip.git”
plugin: country_select: git://github.com/rails/country_select.git

Having an issue uploading/displaying images pushed to Amazon S3 through paperclip (GEM)
Error: undefined method `avatar_file_name’ for #Player:0x00000102aff228

For the most part I was following the example on the git-hub page for paperclip
https://github.com/thoughtbot/paperclip

Here is what I have in my code:

Migration: 20111224044508_create_players.rb

class CreatePlayers < ActiveRecord::Migration
  def change
    create_table :players do |t|
      t.string :first_name
      t.boolean :first_name_public, :default => false
      ...
      t.string :website
      t.boolean :website_public, :default => false
      t.has_attached_file :avatar

      t.timestamps
     end
  end
end

Model: Player.rb:

class Player < ActiveRecord::Base
  attr_accessible :first_name, ... :website 
  validates_presence_of :username, :email

  has_attached_file :avatar, 
                    :styles => { :medium => "300x300>", :thumb => "100x100>" },
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :path => ":class/:id/:style/:filename"

  {Unrelated validations}
end

S3 file: s3.yml

development:
    bucket: voh_development
    access_key_id: *********************
    secret_access_key: ********************
staging:
    bucket: voh_staging
    access_key_id: *********************
    secret_access_key: ********************
production:
    bucket: voh_production
    access_key_id: *********************
    secret_access_key: ********************

Controller: players_controller.rb

class PlayersController < ApplicationController

  def create
    @player = Player.create(params[:player])

    if @player.save 
      redirect_to players_path, :notice => "Player Created"; 
    else 
      render :action => 'new' 
    end
  end

  {basic restful}

end

Views:
Edit.html.haml + New.html.haml

= simple_form_for @player do |f|
  = f.input :first_name
  ...
  = f.input :website
  = f..file_field :avatar 
  .input_div      
    = f.button :submit

index.html.haml

    ...
    %td Avatar
    %td First Name
    ...
    %td Actions
  - @players.each do |player|
    %tr
      %td
        = image_tag @player.avatar.url(:thumb)
      %td
        = player.first_name
      ...
      %td
        = link_to ' Show ', player_path(player.id)
        |
        = link_to ' Edit ', edit_player_path(player.id)

show.html.haml

= image_tag @user.avatar.url
%br
= @player.first_name
...

Research:
I found a lot to do with the pluging and genration of the migration but it all seems old. Most of them suggest putting in the up down in the migration for the 4 attributes. However it seems that should have been replaced by the one line t.has_attached_file :avatar.

I have a rails 3.0 project and this worked. I am able to upload products and pull them back down. (had to play with the suggested image_tag @icon.avatar.url and turned it into %img{:src => URI.unescape(icon.icon.url)} but that a different question.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:32:48+00:00Added an answer on May 28, 2026 at 3:32 am

    TLDR: Fixed typo in index.html.haml from @player => player, Added :avatar to attr_accessible.

    I woke up this morning and had a different error.

    instead of: undefined method Avatar_file_name'

    I got: undefined method avatar' for nil:NilClass

    That error was caused buy a simple type in my code. I used an instance vairable instead of .each variable I should have been using (index.html.haml:9)

    Now the app was not erring out but the file was still not uploading.
    In the development log I found this. (I did not look here the first time I posted)

    WARNING: Can’t mass-assign protected attributes: avatar

    I then went and added :Avatar to attr_accessible and everything started working.

    Not sure if this is supposed to be required or not but I did see that they had updated S3 header to be a proc yesterday.
    https://github.com/thoughtbot/paperclip/tree/master/test/storage

    I am not going to close this out yet. There will be an edit because I am going to play with the version and quickly report my findings today. Then I will close this out.

    Edit:
    I tryed switch back to 2.4.5 and I am getting the error that made me switch to pulling master in the first place. When attempting to do a migration with t.has_attached_file :avatar it fails to migrate and gives the following error.

    undefined method `has_attached_file’ for #ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x00000105053600

    I think I will stick with pulling from master.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using gem rapns (https://github.com/ileitch/rapns) on my rails app. According to rapns doc, I
I'm using gem bundler (v.0.9.6) and Rails 2.3.5, rubygems 1.3.6 and ruby 1.8.7 (On
I wanted to create an online shop using rails and the spree gem (http://spreecommerce.com/).
Using Ruby on Rails, if I do a gem help install a part of
I tried to run rails/generate paperclip photo data and the following error occured: C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/rubygems_integrat
I did: gem install ruby-debug Then it installs... I launched using: rails server -u
I have a Ruby application (not using Rails) that use my own Ruby gems.
I'm relatively new to Ruby on Rails. I'm using a particular gem my_gem in
I am using Ruby on Rails 3.1.0 and the Capistrano gem and I created
I am using Ruby on Rails 3.1.0 and the Capistrano gem. As wrote in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.