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.
Related
When migrating the database, I made a spelling mistake.
I want to generate a scaffold by running:
rails generate scaffold Micropost context:text user_id:integer
rails db:migrate
Although I made a mistake by leaving out the colon when I ran:
rails generate scaffold Micropost context:text user_id integer
rails db:migrate
I want to undo this migration, how to do it?
(I'm using Rails 5.0.0.1)
When I run rails db:migrate, I get an error of:
SQLite3::SQLException: table "microposts" already exists:
When I run rails db:migrate:status, I get the following output:
Status Migration ID Migration Name
up 20161024021157 Create users
up 20161024025545 ********** NO FILE **********
down 20161024025805 Create microposts
I tried to use rails db:migrate:down VERSION=20161024025805. There wasn't any message showing in the command line. Then I ran rails db:migrate. The error is the same.
rails db:rollback will simply rollback one migration which I believe is what you are looking for
For a more specific rollback, you can run rails db:migrate:down VERSION=numberofversion
Replace the numberofversion with the version number of the migration file generated, for example:
rails db:migrate:down VERSION=1843652238
Edit:
Since you are getting the error that the Microposts table already exists, you must follow these steps to remove the table:
Run rails generate migration DropMicroposts
Go to the /db/migrate folder and find the latest migration file you just created
In that file paste this:
class DropMicroposts < ActiveRecord::Migration
def up
drop_table :microposts
end
end
run rails db:migrate
After this, run rails generate scaffold Micropost context:text user_id:integer
Then run rails db:migrate
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 defined a model in rails using command rails generate model testdetails . After that I went to db/migrate and wrote the fields for this model
class CreateTestDetails < ActiveRecord::Migration
def self.up
create_table :test_details do |t|
t.column :TestName ,:string
t.column :TestType ,:integer
end
end
end
then i did db:migrate , it throws some error . I google it and found out that it may be coming due to devise version ( I am using devise for authentication) , I updated Gemfile and wrote the version of devise (2.1) and did bundle install . After that I again did db : migrate but it is showing this error
rake aborted!
undefined method secret_key=' for Devise:Module
/home/vibhor/rails_projects/recruit/config/initializers/devise.rb:7:inblock in '
/home/vibhor/rails_projects/recruit/config/initializers/devise.rb:3:in <top (required)>'
/home/vibhor/rails_projects/recruit/config/environment.rb:5:in'
Tasks: TOP => db:migrate => environment
what should i do so that this model can be created without any error? i am using rails 3.2.13 and ruby 2.0.0
I think this is due to gem version so update it to latest version 3.x or remove that line from your config/initializers/devise.rb file.
In your config/initializers/devise.rb file add this line:
config.secret_key = 'Your secret Key'
And use rake secret to generate your secret key.
There's an issue open in github if you need more info.
Had the same problems lately. Check devise initializers, as it has changed lately. For me it solved the problem.
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 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.