can't install paperclip rails 3.0.7 - ruby-on-rails

I am still new to rails 3 and the different commands to use in terminal. I have tried to use the $ rails plugin install git://github.com/thoughtbot/paperclip.git command but everytime I hit enter, it just brings up my options when I use rails new, like -v tell your the version or -b is the builder. I don't know whats wrong

Agree with the above, gem is the way to go. Just add to you Gemfile:
gem 'paperclip', '2.3.3'
and run:
bundle install
Should be as easy as that to get paperclip running. Don't forget to include the 3 migration parts when binding to a model (example for video). In this case I am adding paperclip as 'attachment' to my Video model. Just slap 'file_name', 'content_type', and 'file_size' to the end of the downcased attribute:
class AddVideoAttachment < ActiveRecord::Migration
def self.up
add_column :videos, :attachment_file_name, :string
add_column :videos, :attachment_content_type, :string
add_column :videos, :attachment_file_size, :integer
end
def self.down
remove_column :videos, :attachment_file_size
remove_column :videos, :attachment_content_type
remove_column :videos, :attachment_file_name
end
end

I recommend you to install Paperclip as a gem, not as a plugin. Installing as a plugin can lead to all sorts of issues.
GitHub paperclip sites states specifically:
"Paperclip is distributed as a gem, which is how it should be used in your app. It's technically still installable as a plugin, but that's discouraged, as Rails plays well with gems."
Visit GitHub/Paperclip and install Paperclip as a gem and you should be fine.

Related

Trouble adding st_point column with activerecord-postgis-adapter

This is a pretty verbatim copy of what I wrote on the project github. Forgive me for cross posting but I was hoping someone here had come across this error:
undefined method `st_point' for #
<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x0055cdd8f278e8>
This is my Gemfile lock:
activerecord (4.2.7.1)
activerecord-postgis-adapter (3.1.4)
and the migration:
class CreateLocations < ActiveRecord::Migration
def change
enable_extension "postgis"
create_table :locations do |t|
t.st_point :geom, geographic: true, srid: 4326, dimension: 2
t.timestamps
end
end
end
What's wierd is that this works in development mode. It's just when I run the migrations for the test environment that it fails.
After rake db:create RAILS_ENV=test, I have conntected to the test database with psql and run CREATE EXTENSION postgis;.
tl;dr
t.st_point in the migration is undefined, only in the test environment.
The error was "postgres" instead of "postgis" in the ENV["DATABASE_URL"]
That it what others suggested on the thread. I was being stubborn by not checking for this, but it turns out to be the correct cause.

Why am I getting a method undefined error in rails?

I'm working on letting users sign in and out of my rails app. The error I get is as follows
undefined method 'find_by_remember_token'
The method in question is written like this:
def current_user
#current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
Any help you can provide in fixing this error would be greatly appreciated!
you can reset your database and migrate in one line:
rake db:migrate:reset && rake db:migrate && annotate
use the gem annotate in your project to have a better view of your database columns
in your Gemfile add:
gem 'annotate'
and in console run:
bundle update && bundle install
You don't have a field in your users table called remember_token ?
I know this is an old question, but I had the same problem and wanted to include how I fixed it.
First, I made sure I added the required info to the migration:
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end
then I just dumped my db and remigrated:
rake db:drop
rake db:create
rake db:migrate
worked for me after that.

Rails Gem::LoadError in UsersController#new

New to Ruby on Rails and having a problem when following Michael Hartl's tutorial.I'm using Rails 3.2.2 with Ruby 1.9.3. The issue looks very similar to another question that was raised but was unanswered:
Rails Error NoMethodError in UsersController#show error
I get the following error when attempting to add a new user via /signup
Gem::LoadError in UsersController#new
bcrypt-ruby is not part of the bundle. Add it to Gemfile.
Reloading the page gives the error:
NoMethodError in UsersController#new
undefined method `key?' for nil:NilClass
The problem seems to be related to the inclusion of the bcrypt-ruby gem, and the usage of the has_secure_password method in user.rb . Removing the call to has_secure_password in user.rb gets rid of the error and it goes to the signup page successfully.
user.rb:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# password_digest :string(255)
#
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
validates :name, presence: true, length: { maximum: 50 }
valid_email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: valid_email_regex },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6}
end
users_controller.rb:
class UsersController < ApplicationController
def new
#user = User.new
end
def create
#user = User.new(params[:user])
if #user.save
flash[:success] = "Welcome!"
redirect_to #user
else
render 'new'
end
end
end
However, I cant find anything wrong with the inclusion of the bcrypt-ruby gem. In the Gemfile I have:
gem 'bcrypt-ruby', '3.0.1'
and the gem has also been generated in Gemfile.lock :
DEPENDENCIES
annotate (~> 2.4.1.beta)
bcrypt-ruby (= 3.0.1)
I've also added password_digest to the database via migration:
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
Any ideas ?
I'm going through the same tutorial and encountered the exact same problem.
My solution was to restart the web server. After installing the gem, I think the web server needs to be restarted so it is loaded.
Justin
Did you tried the 'bundle update' command, usually the bundler will take care of gems if you specified in the Gemfile. If you want to check the gem dependency please check http://rubygems.org/gems.
And if you are using windows(I know its strange- but some of our app works in windows only) there is some tricks to install bcrypt
Steps to install bcrypt.
1 Download Devkit and extract
you can download it from here http://rubyinstaller.org/downloads/
2 Place devkit it your jruby folder (in my case C:\applications\jruby\devkit)
3 You need to install ruby as well either 1.8.7 or 1.9(some times needs a system restart)
4 CD into devkit directory
5 Run ruby dk.rb init
6 Open config.yml and make sure that both your jruby installtion is listed. If not, ADD them. Save and close config.yml after you're done.
example:- C:/applications/jruby
7 Run ruby dk.rb install
8 jruby -S gem install bcrypt-ruby
Restarting the web server fixed it for me (had spork running in the background to speed up the running of the tests)

using delayed_paperclip gem with delayed_job gem

i am working on a simple rails project and i use paperclip to upload attachments but when ever i use delayed job gem with delayed_paperclip gem i dont see the attachment. I followed the rdoc and tried it out but my guess is that i am not running delayed job well.
my attachment.rb lookes like this
has_attached_file :file
process_in_background :file
and i added this to my database
class AddFileProessingToAttachments < ActiveRecord::Migration
def change
add_column :attachments, :file_processing, :boolean
end
end
what else do i need to do again because i have waited for a long time and i still have a missing file.
I just realized that i have to start the delayed job task with the following command.
rake jobs:work
did not know until i checked my list of rake tasks

rails migration version issue: any new migration not working

From this morning, I am facing weird issues with Rails devise. Following is output of my ls and rake db version command.
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$ ls -1
20120110083934_devise_create_users.rb
20120110090514_create_posts.rb
20120110090845_add_user_id_to_post.rb
20120203035323_add_confirmable_to_devise.rb
20120203035323_add_confirmable_to_devise.rb~
20120203043601_add_lockable_to_devise.rb
20120203043601_add_lockable_to_devise.rb~
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$ rake db:version
(in /home/hrishikesh/git-public/personaldiary)
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead. (called from /usr/lib/ruby/vendor_ruby/activerecord.rb:2)
Current version: 20120203034555
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$
If I try to add any new migrations, rake db:migrate throws error that tells me that some column already exists, and fails.
My failing migration code is here:
class AddConfirmableToDevise < ActiveRecord::Migration
def change
change_table(:users) do |t|
t.confirmable
end
add_index :users, :confirmation_token, :unique => true
end
end
I specifically do not want to use up and down methods because of this
Please help.
After spending hours to find solution, I decided to give up and ran
rake db:migrate:reset
And it worked, only thing is my data was lost, which was not that big deal at this point.
Thank you everyone for attempting to solve this.

Resources