Why do I set the undefined method to has_attached_file when installing PaperClip?

I just installed the plugin for Paperclip and I am getting the following error message, but I'm not sure why:

NoMethodError (undefined method `has_attached_file' for #<Class:0x10338acd0>): /Users/bgadoci/.gem/ruby/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing' app/models/post.rb:2 app/controllers/posts_controller.rb:50:in `show' 

This is a link to the will_paginate gem. From what I can find, it seems that something is wrong with my PostsController#index or there may have been an earlier attempt to install a gem instead of a plugin, in which case I read that I could fix it through /config/environments.rb file somehow.

I did not think that a previous installation of gem would have mattered since I did this in the old version of the site, which I crashed before installing the plugin. In the current version of the site, I show that after the migration, the table has been updated with Paperclip columns. Here is my code:

PostsConroller#show :

  def show @post = Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @post } end end 

Post Model:

 class Post < ActiveRecord::Base has_attached_file :photo validates_presence_of :body, :title has_many :comments, :dependent => :destroy has_many :tags, :dependent => :destroy has_many :votes, :dependent => :destroy belongs_to :user after_create :self_vote def self_vote # I am assuming you have a user_id field in `posts` and `votes` table. self.votes.create(:user => self.user) end cattr_reader :per_page @@per_page = 10 end 

/views/posts/new.html.erb :

 <h1>New post</h1> <%= link_to 'Back', posts_path %> <% form_for(@post, :html => { :multipart => true}) do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.label :body %><br /> <%= f.text_area :body %> </p> <p> <%= f.file_field :photo %> </p> <p> <%= f.submit 'Create' %> </p> <% end %> 
+49
ruby ruby-on-rails paperclip
Apr 18 2018-10-18T00:
source share
5 answers

It is very important to restart the server after installing new gems / plugins. This should solve your problem.

+170
Jul 30 '10 at 16:30
source share

I would suggest installing paperclip gem. Then you just need to add config.gem 'paperclip' to your environment.rb and run sudo rake gems:install .

+8
Apr 18 '10 at 5:14
source share

create paperclip.rb file inside config / initializers / paperclip.rb

Add the lines below and restart the server

paperclip / railtie required

Paperclip :: Railtie.insert

+1
Sep 12 '15 at 12:02
source share

I got this error spontaneously on two different dev machines after Paperclip worked perfectly for several weeks.

spring stop

Then my rail console rebooted.

+1
Apr 26 '17 at 15:14
source share

I think this should have been obvious, but I use mongo / mongoid as my data level and you need to set mongoid paperclip for it to work.

0
Oct 03 '13 at 17:23
source share



All Articles