I'm reading the book Learning Rails by O'Reilly and it recommends using the validate_existence_of plugin. When I run:
ruby script/plugin install http: //svn.hasmanythrough.com/public/plugins/validates_existence/
it says it's already installed, but when I use it, I get a message saying:
NoMethodError in AwardsController#index
undefined method `validates_existence_of' for #<Class:0xb5fde868>
When I say:
class Award < ActiveRecord::Base
belongs_to :student
validates_existence_of :student
end
Any ideas?
Have you checked that the plugin code is installed in the vendor/plugins directory ?
Also you may need to check that the environment.rb file has the config.gem section uncommented.
Related
I am following the directions from the gem's GitHub repo:
I added fuzzily to my gem file and ran rake db:install. Fuzzily 0.3.3 was successfully installed.
I created a app/models/fuzzily.rb file:
class Trigram < ActiveRecord::Base
include Fuzzily::Model
end
I then created a migration for it:
class AddTrigramModel < ActiveRecord::Migration
extend Fuzzily::Migration
end
And ran: rake db:migrate, which created a trigrams table with the fields: id, trigram, score, owner_id, owner_type, fuzzy_field
I then modified my app/models/organization.rb and added the following:
fuzzily_searchable :org_name
I saved all my work and started the console:
rails c
then:
Lobbyist.connection
Followed by:
Lobbyist.bulk_update_fuzzy_name
To which I am getting an error message: undefined method .bulk_update_fuzzy_name
My environment is:
Ruby 2.1.5
Rails 4.2.1
Any ideas?
The name part in bulk_update_fuzzy_name is actually the name of the searchable field, so in your case it would be Lobbyist.bulk_update_fuzzy_org_name. The same applies to other method calls in the readme.
I am using 'acts_as_messagable' gem for private messaging between users.
My model:
class User < ActiveRecord::Base
acts_as_messageable :table_name => "messages"
..
end
I have error on start application:
`method_missing': protected method `default_scope' called for #<Class:0x007f84d7870da8> (NoMethodError)
current rails version 4.1, migrations are done.
What is the root of problem?
It's not compatible from the docs:
the gem is compatible with Rails 2.3, an upgrade to Rails 3 is planned
I attempted to install the gmaps4rails gem.
I added gem 'gmaps4rails' to my Gemfile, and ran 'bundle install. It said that my bundle installed successfully. I can find "Using gmaps4rails (0.8.8)" with 'gem list'. I added the specified columns to my users table with rake db:migrate and added acts_as_gmappable and the gmaps4rails_address method to my User model.
Visiting pages that involve the user model gives me "undefined local variable or method 'acts_as_gmappable'"error.
Is there something that I am missing?
For greater context, the code I am using is from the Rails 3 Tutorial.
OS X 10.6.6
ruby 1.8.7
rails 3.0.7
passenger 3.0.7
Restarting the server should resolve the problem :)
I had the same issue : undefined local variable or method 'acts_as_gmappable'
I just restarted the server and it error went away.
I was using Mongoid and had the same trouble.
In which case, make sure your model includes:
include Gmaps4rails::ActsAsGmappable
acts_as_gmappable :position => :location
field :gmaps, :type => Boolean
field :location, :type => Array
def gmaps4rails_address
#describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
"#{self.address}, #{self.city}, #{self.country}"
end
I think this may be helpful (similar issue):
rvm + rails3 + gmaps4rails - acts_as_gmappable
I'm getting an error that acts_as_authentic is undefined for rails 3, ruby 1.9.2
My Gemfile has: gem 'authlogic'
The command "bundle show authlogic" shows the correct path where authlogic is installed
My acts_as_authentic appears in a controller:
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :phone
end
end
Let me know if there's anything else that will be helpful, I'm new to rails so I'm not entirely sure what to post.
Thanks
For some reason I always ask questions on StackOverflow just before I figure it out. I needed to restart rails server to get it to work.
I'm trying to use oauth-plugin on a Rails application I'm developing, but I keep running into problems.
To make sure I'm not making any mistake, I started an application from scratch (using Rails 3.0.3). Here are the steps I followed:
Create da new rails application (rails.test)
Edited its Gemfile to include:
gem "oauth-plugin", ">=0.4.0.pre1"
gem "oauth", "0.4.4"
Generated oauth-consumer, by running script/rails g oauth_consumer
Edited oauth_consumers.rb to include my keys for Google integration:
:google=>{
:key=>"anonymous",
:secret=>"anonymous",
:scope=>"https://www.google.com/calendar/feeds/",
:options => {
:site => "http://www.google.com",
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken"
},
}
Edited routes.rb to add the route for oauth_consumer:
resources :oauth_consumers
Edited application_controller.rb to implement the logged_in? method as follows:
def logged_in?
true
end
Now when I access http://localhost:3000/oauth_consumers/google I get the following error:
uninitialized constant GoogleToken
Does anyone know what causes this error and how can I fix it? GoogleToken is a class that should have been auto generated by oauth-plugin, so I can't tell why I'm getting this uninitialized constant error.
The GoogleToken class doesn't get auto-generated unless you pass "google" to the generator like so:
script/rails g oauth_consumer google
or for rails 3:
rails g oauth_consumer google
Also check to ensure the relationship is set up in the user model like so:
has_one :google, :class_name => "GoogleToken", :dependent => :destroy
Did you remember to run bundle install from terminal after editing your Gemfile? Sounds like your Rails app doesn't know about these gems yet.
I have the same problem, i think a solution could be in this:
https://github.com/pelle/oauth-plugin/blob/master/lib/generators/oauth_consumer/USAGE
You need some sort of authentication like restful-authentication plugin, if you uncomment line 27..29 in your oauth_consumers_controller.rb file, you'll jump to next step!