I'm facing joins association issue in Rails 5.2.1, below query working properly in rails 5.2.0 but not in 5.2.1
User.joins(:roles).where(email: 'test#gmail.com', roles: {titles: ['test1', 'test2']})
Here relation between user and roles had has_many, following error I'm getting while running this query in rails console.
ArgumentError: wrong number of arguments (given 3, expected 2)
from /Users/testuser/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/associations/join_dependency/join_association.rb:12:in `initialize'
Related
Getting below error message when running Rspec after upgrading Ruby to 3.0.3
Failure/Error: FactoryBot.lint strategy: :build_stubbed
FactoryBot::InvalidFactoryError:
The following factories are invalid:
user - wrong number of arguments (given 1, expected 0; required keywords: event_type, object, summary, author) (ArgumentError)
I'm using rails 5.1.4
devise 4.4.1
factory_bot_rails 4.8.2
rails g devise User
Running via Spring preloader in process 15889
invoke active_record
create db/migrate/20180213152941_devise_create_users.rb
create app/models/user.rb
invoke rspec
create spec/models/user_spec.rb
error factory_bot_rails [not found]
insert app/models/user.rb
route devise_for :users
Thanks for replay, the problem was that in config/application.rb, fixture_replacement need to pass :factory_bot and not factory_bot_rails, reading the doc I see that are distinct gems.
I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.
abhishek#abhishek ~/my_app (master●●)$ rails c [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class
Please note: I am intentionally calling page without any arguments to reproduce the issue.
Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.
I have realized this late and fixed.
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
Have a look at this tutorial https://github.com/amatsuda/kaminari
This is how it works
User.page(page_number).per(records_per_page)
I upgraded my rails version to 4.1.1 from 4.0.4.
Whenever I run rake test I get every test having this error:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "roles_users" does not exist
LINE 1: DELETE FROM "roles_users"
^
: DELETE FROM "roles_users"
My user controller has and belongs to many roles
has_and_belongs_to_many :some_names,
class_name: "Role",
join_table: "some_names_users"
So it should not be looking for roles_users as a table, but seems to be in the fixtures for my tests.
I am using minitest 5.3.4. I am not using the gem turn.
This is a bug in Rails 4.1; it's already been fixed and I'd expect it to be part of the next release (4.1.2).
In the mean time, you might be able to use the 4-1-stable branch:
gem 'rails', github: 'rails/rails', branch: '4-1-stable'
Github Issues:
Habtm join_table option is not recognized in fixtures
Fix to use custom join table in habtm
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