I am working with Twitter's new activerecord-reputation-system gem, yet it doesn't seem to be registering in my app.
I ran to install (docs have a typo):
gem install activerecord-reputation-system && rails generate reputation_system && rake db:migrate
I've included it in my gemfile and tried pulling directly from github, as well as restarting my local server. The error is the following:
ActionController::RoutingError (undefined method has_reputation' for #<Class:0x007fa7ed783ec0>):
app/models/post.rb:18:in'
app/models/post.rb:1:in <top (required)>'
app/controllers/posts_controller.rb:1:in'
when I try to add votes to posts with this code:
class Post < ActiveRecord::Base
belongs_to :user
has_reputation :votes,
:source => :user,
:aggregated_by => :sum
end
When I try to add votes to users with the same code I get:
undefined method `has_reputation' for #<Class:0x007fa7efb70388>
app/models/user.rb:17:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
config/routes.rb:4:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
This error occurred while loading the following files:
/Users/username/appname/config/routes.rb
routes.rb, Line 4:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
Any ideas?
You should require reputation_system in your app. You can do this by adding to your Gemfile:
gem 'activerecord-reputation-system', :require => 'reputation_system'
Update: As of version 2.0.0 you don't need to require reputation_system anymore:
gem 'activerecord-reputation-system'
Related
Hello Programmers & Developers!!!, I'm facing a problem in rails console when I tried to access DeviseMultipleTokenAuthDevice then I'm getting the following error :
Loading development environment (Rails 4.2.0)
2.2.4 :001 > DeviseMultipleTokenAuthDevice
NameError: uninitialized constant DeviseMultipleTokenAuthDevice
from (irb):1
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
2.2.4 :002 >
Following gems I'm using in my project for user authentication
gem 'devise'
gem 'devise_multiple_token_auth'
Following are the tables in my record :
2.2.4 :002 > p ActiveRecord::Base.connection.tables
["schema_migrations", "users", "devise_multiple_token_auth_devices"]
=> ["schema_migrations", "users", "devise_multiple_token_auth_devices"]
2.2.4 :003 >
For more info you can follow these links :
Source from where I followed the instruction
My Github repo link for project source
Other required information
Ruby Version 2.2.4
Rails Version 4.2.0
Database PSQL
The solution for the same is, we've to create a file called devise_multiple_token_auth_device.rb in app/models/
here is the code for devise_multiple_token_auth_device.rb file
class DeviseMultipleTokenAuthDevice < ActiveRecord::Base
belongs_to :user
end
This is my first time importing a csv file to my rails app.
I have the code below in /lib/tasks/import.rake
require 'csv'
CSV.foreach("lib/articles.csv", headers: true, encoding: "ISO8859-1") do |row|
Article.new(title: row["Title"], body: row["Body"], user: User.find(1))
end
When I run rake import:articles
I get this error:
NameError: uninitialized constant Article
/Users/justinMgrant/code/hrsurvival/lib/tasks/import.rake:8:in `block in <top (required)>'
/Users/justinMgrant/code/hrsurvival/lib/tasks/import.rake:7:in `<top (required)>'
/Users/justinMgrant/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/engine.rb:658:in `block in run_tasks_blocks'
/Users/justinMgrant/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/engine.rb:658:in `each'
/Users/justinMgrant/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/engine.rb:658:in `run_tasks_blocks'
/Users/justinMgrant/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application.rb:452:in `run_tasks_blocks'
/Users/justinMgrant/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/engine.rb:453:in `load_tasks'
/Users/justinMgrant/code/hrsurvival/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)
Any idea what I’m doing wrong?
The problem is that you're not actually defining your task in your rakefile. This should work for you to be able to run rake import:articles.
namespace :import do
desc 'An optional description for what the task does'
task :articles => :environment do
# your code goes here
end
end
rake import:articles is saying to look for a task called articles within a namespace called import, which is why the namespace is necessary for what you're currently trying.
And as #max mentioned, utilizing task :articles => :environment is what tells the task to run in the context of your Rails environment, which would make your Articles model and any other model available to you in that task.
This code for class assignment is ok until rails v4.0.5
but it make an error from rails 4.1.x
there is a api documentation so I guess that it is not deprecated.
I can not know what is the problem of this.
Loading development environment (Rails 4.1.1)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
NameError: undefined local variable or method `generated_feature_methods' for #<Class:0x0000010a262e28>
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:30:in `block in accepts_nested_attributes_for'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `each'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `accepts_nested_attributes_for'
from (irb):4:in `<class:Assignment>'
from (irb):1
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It is ok on Rails 4.0.5
Loading development environment (Rails 4.0.5)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
=> [:event]
Possible duplicate of Rails 4.1.0.beta1 upgrade gives me undefined local variable or method generated_feature_methods. Like it says there, try updating the protected_attributes gem:
bundle update protected_attributes
I enabled Refinery Search and Refinery Blog extensions in Gemfile and run rake db:migrate, rake db:seed.
And per Refinery Search instructions file, added the following to config/application.rb
config.to_prepare do
Refinery.searchable_models = [Refinery::Blog]
end
And also created app/decorators/models/refinery/blog_decorator.rb with
Refinery::Blog.class_eval do
acts_as_indexed :fields => [:title, :body, :custom_teaser]
end
Above example is from: http://refinerycms.com/guides/extending-model
But when I try to run rails c or rails s, there is an error:
=> Ctrl-C to shutdown server
Exiting
/home/bismailov/Desktop/my_docs/Inbox/ror/maqolarefinery/app/decorators/models/refinery/blog_decorator.rb:2:in `block in <top (required)>':
undefined method `acts_as_indexed' for Refinery::Blog:Module (NoMethodError)
from /home/bismailov/Desktop/my_docs/Inbox/ror/maqolarefinery/app/decorators/models/refinery/blog_decorator.rb:1:in `class_eval'
What could I be missing here? Thank you a lot!
Actually Refinery::Blog is a module not a model. Ideally you should use Refinery::Blog::Post.
I am beginning to write tests for an application and I'm having trouble getting the test environment to work.
My system has Paperclip for file uploads and it's tripping up at any attempt to start the server or even to initialize a new company record! An example:
# Company.rb line 3
has_attached_file :photo,
:styles => {:medium => "200x300>", :thumb => "100x150>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/photos/:style/:id/:basename.:extension"
# console
ruby-1.9.2-p0 :001 > Company.new
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=
from /Users/san/Documents/san/app/vendor/plugins/paperclip/lib/paperclip.rb:232:in 'has_attached_file'
from /Users/san/Documents/san/app/app/models/company.rb:3:in '<class:company>'
from /Users/san/Documents/san/app/app/models/company.rb:1:in '<top (required)>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'block in load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in 'new_constants_in'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in 'load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in 'require_or_load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in 'load_missing_constant'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in 'block in const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'each'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in 'const_missing_from_s3_library'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing'
from (irb):1
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in '<top (required)>'
from script/rails:6:in 'require'
Do you know what's causing this conflict and how I can fix it?
I read through the Paperclip docs and I discovered the need to add:
require 'paperclip/matchers'
Spec::Runner.configure do |config|
config.include Paperclip::Shoulda::Matchers
end
to spec_helper.rb. Still getting the same error!
I reckon what that is is the s3.yml doesn't contain a key for your current Rails environment, probably test? Add one. That should fix it!
In the end the error was fixed by downgrading Paperclip to 2.3.6, which is what I was using up until a week ago. Hopefully this is helpful to anyone experiencing this error in the future!