I'm trying to use the gravatar_image_tag RoR plug-in and it is giving me this error, when I start up the rails console or the rails server. What do I do to fix it?
/Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb:66: uninitialized constant ActionView::Helpers::AssetTagHelper::AssetPaths::Mutex (NameError)
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3:in `require'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers.rb:39
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/base.rb:134
from /Library/Ruby/Gems/1.8/gems/gravatar_image_tag-1.0.0/lib/gravatar_image_tag.rb:97
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler.rb:120:in `require'
from /Users/pickhardt/projects/sample_app/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48
from script/rails:6:in `require'
from script/rails:6
It's possible your plugin isn't compatible with your version of rails. Gravatar images aren't that hard to do with out a plugin. Here is a solution by Ryan Bates for Gravatars
application_helper.rb
def avatar_url(user)
if user.avatar_url.present?
user.avatar_url
else
default_url = "#{root_url}images/guest.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
end
end
users/index.html.erb
<%= image_tag avatar_url(user) %>
Related
I'm pretty sure that the problem is due to the fact that this gem looks to be 3-4 years old and rails has changed how we do migrations. But I'm not too familiar with gems/generators. I'm trying to follow the instructions to do the instructions listed here.
rails g my_zipcode_gem:models
rake db:migrate
rake zipcodes:update
However, when I do the first step I end up getting this:
/Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:35:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators/migration.rb:63:in `migration_template'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:36:in `create_migration'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators.rb:157:in `invoke'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/generate.rb:11:in `<top (required)>'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:135:in `generate_or_destroy'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Any idea what I need to do to get that gem working? It provides exactly what I'm looking for in my app.
Thanks!
Edit: Adding the generation code:
module MyZipcodeGem
class ModelsGenerator < Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def initialize(*args, &block)
super
end
def generate_models
# puts ">>> generate_zipcodes:"
end
def add_gems
add_gem "mocha", :group => :test
end
def create_models
template 'zipcode_model.rb', "app/models/zipcode.rb"
template 'county_model.rb', "app/models/county.rb"
template 'state_model.rb', "app/models/state.rb"
end
# Implement the required interface for Rails::Generators::Migration.
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end
def create_migration
migration_template 'migration.rb', "db/migrate/create_my_zipcode_gem_models.rb"
end
def create_rakefile
template 'zipcodes.rake', "lib/tasks/zipcodes.rake"
end
end
end
# /Users/cblackburn/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/rails/generators/active_record/
It looks like it is calling the migration using parameters that are no longer expected. You have two options:
1) fork the code, update it to use rails 4 conventions, and create a pull request on github. Assuming the owner is still active they will bring your code into the master and republish the gem. You would have help support the community and feel good about it in the process. There are plenty on here like myself who can help you with this.
2) Find another gem to do what you want, such as http://www.rubygeocoder.com/ which I've used several times and is awesome at doing location/zipcode problems
I'm trying to run scrapi with rails with this code:
require 'rubygems'
require 'scrapi'
require 'tidy'
scraper = Scraper.define do
process "title", :page_name => :text
result :page_name
end
uri = URI.parse("http://railscasts.com/episodes/173-screen-scraping-with-scrapi")
p scraper.scrape(uri)
but I get the following error:
DL is deprecated, please use Fiddle
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:5:in `<class:Tidybuf>': uninitialized constant DL::Importable (NameError)
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:3:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:25:in `<module:Tidy>'
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:21:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from scrapitest.rb:3:in `<main>'
has anybody got an idea why is that and what could I do to fix it?
Thank you.
Try http://github.com/libc/tidy_ffi instead. It seems tidy gem is not mantained anymore.
I'm using the rails-settings gem: https://github.com/huacnlee/rails-settings-cached
The getter/setter method are not working.
I've added the following line to my user model as directed:
include RailsSettings::Extend
I've also tried adding it to role.rb (as I am using rolify gem)
However is am still getting the following error message:
NoMethodError: undefined method `settings' for #<User:0x007f8dd017a560>
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/activerecord-3.2.13/lib/active_record/attribute_methods.rb:149:in `method_missing'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/rolify-3.2.0/lib/rolify/role.rb:73:in `method_missing'
from (irb):24
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
When I run:
user = User.find(2)
user.settings.color = :red
Can anyone see what the issue is?
Ok, I've solved the issue.
I had not restarted the console session.....restarting it got it working!
Trying to learn the Ruby on Rails 3 Tutorial book, hung up right now: Section 2.2
example says:
rails generate scaffold User name:string email:string
I get:
C:\Sites\rails_projects\demo_app>rails generate scaffold User name:string email:
string
C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:
34:in `require': wrong number of arguments (0 for 1) (ArgumentError)
from C:/Sites/rails_projects/demo_app/Gemfile:4:in `evaluate'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/dsl.rb:7:in `instance_eval'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/dsl.rb:7:in `evaluate'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/definition.rb:17:in `build'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:138:in `definition'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:126:in `load'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:110:in `setup'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/setup.rb:7:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:57:in `require'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:57:in `rescue in require'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:35:in `require'
from C:/Sites/rails_projects/demo_app/config/boot.rb:6:in `<top (require
d)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from script/rails:5:in `<main>'
Can someone please set me on the right track? Thanks!
i dont know if you are a new comer to rails 3 but if not and also if you are, i think DEVISE is a good gem to use .i have finished the book and i used devise for my authentication system. all you need do is install it manually from github so as to read its documentation and also more tutorials on ASCiiCast and railscast for videos (engaging with devise). it as a lot of methods that is used in the book e.g if signed_in, current_user, logged_in e.t.c and also destroy the user model before using DEVISE.
I would review your Gemfile to see that you have everything entered correctly.
HTH
I've authored a module that lives in my lib folder. I'm including it at startup by putting it in my environment.rb file as follows
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
MyProject::Application.initialize!
ActiveRecord::Base.send :include, MyProject::Has::Formatter
include MyProject::EventFormatters
This works great in development but if I try to run in production mode or if I deploy my app to production I get the following stack trace when the server tries to start up:
=> Booting WEBrick
=> Rails 3.0.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in `method_missing': undefined local variable or method `has_formatter' for #<Class:0x808f830> (NameError)
from C:/Data/myproject/app/models/event.rb:2
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:227:in `load_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:346:in `require_or_load'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:300:in `depend_on'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:216:in `require_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:138:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:108:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:41
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
from C:/Data/myproject/config/environment.rb:5
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from C:/Data/myproject/config.ru:3
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from C:/Data/myproject/config.ru:1:in `new'
from C:/Data/myproject/config.ru:1
Now here is the most mind boggling part of the whole thing: If I set config.cache_classes = false in config/environments/production.rb then I don't get that stack trace and the app behaves the same in production mode as it does dev mode!!
What about settings config.cache_classes = false makes including a module in this fashion work in production? Am I including the module in a wrong/weird way?
Hope I'm totally, right, I'll at least present my point of view:
In development, all your classes are lazy loaded. This way, you can easily change them since they're loaded only when necessary. This means that:
MyProject::Application.initialize!
does not load module content which requires:
ActiveRecord::Base.send :include, MyProject::Has::Formatter
include MyProject::EventFormatters
which is included afterwards, it makes the whole thing working.
In production, modules and classes are really loaded => crash, they need their dependencies!
As a result, put:
ActiveRecord::Base.send :include, MyProject::Has::Formatter
include MyProject::EventFormatters
in an initializer you create in config/initializers, call it active_record_extension.rb for instance.
Does autoloading not work for your scenario?
# config/application.rb
config.autoload_paths += %W(#{config.root}/lib)
# lib/my_project/event_formatters.rb
module MyProject
module EventFormatters
# .. etc. ...
end
end