letsrate gem wrong number of arguments error - ruby-on-rails

I'm using using letsrate gem and getting the following error:
ArgumentError - wrong number of arguments (3 for 2):
lib/letsrate/lib/letsrate/model.rb:69:in `letsrate_rateable'
app/models/model_definition.rb:3:in `<class:ModelDefinition>'
app/models/model_definition.rb:1:in `<top (required)>'
I've tried to downgrade version from 1.0.9 to 1.0.8 and then I've copied the source to lib directory still I'm getting the same error.

The code shown in the master branch of the letsrate gem shows that the method in question accepts a variable number of arguments.
Try installing the gem from the master branch of GitHub to correct the problem. Add this code to your Gemfile and run bundle install
gem 'letsrate', git: '/muratguzel/letsrate'

Related

What's the replacement for acts_as_commentable in Rails 6, Ruby 3.0.2?

I upgraded our app to Rails 6.1.4.4 and Ruby 3.0.2. I have this old gem
gem 'acts_as_commentable'
Locked at version 4.0.2. The gem does not appear to be supported anymore, which is a shame because when I start up my app or console, I now get this error
$ rails c
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'
…
Is there any simple replacement for this gem or way to monkey-patch this error so I can start up the app?
Looking over the forks, I found this one that appears to work for me using Rails 6.0.6 and Ruby 3.0.5.
https://github.com/alazycoder101/acts_as_commentable.git
I have not tested it extensively yet, but at least the basic functionality seems to be working for me. Hope this helps.
For clarity, to use that fork you would use the following line in your Gemfile:
gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'

Rails 4.2.9 "cannot load such file" (multiple files)

So it's been a while since I fired up the old Rails server. It took a lot of tricks to even get the bundle to install... but eventually I upgraded from Rails 4.2.6 to 4.2.9. The bundle installs just fine. I'm on Ruby 2.3.0. But now the problem is... whenever I try to run:
rails s
I get the following error:
rails-html-sanitizer.rb:2:in `require': cannot load such file -- loofah (LoadError)
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `each'
Or some variation of that.
At first I was getting around this by uninstalling whatever the Gem that was said to be unable to load (in this case "loofah" but I've done it with many more), and then adding it to the Gemfile and installing it using Bundler. I now realize that the list is never-ending:
gem 'rails-html-sanitizer'
gem 'chronic'
gem 'multipart-post'
gem 'oauth-active-resource'
gem 'rack-test'
gem 'multi_json'
gem 'addressable'
gem 'orm_adapter'
All the above couldn't load. I ran Rails for years before this... and I know this isn't the way it's supposed to work. Any help/advice on what could be going wrong?
If you see carefully in the error message, it says ruby-2.3.0#rails3.2.16 but you mentioned "upgraded from Rails 4.2.6 to 4.2.9." . For some reason, it's still referring to rails3.2.16. Therefore it could be you need to install the rails-html-sanitizer globally. By the way, Loofah is only needed if you wanted to use it in a non-rails app. Refer to the docs here.
Rails Html Sanitizer is only intended to be used with Rails
applications. If you need similar functionality in non Rails apps
consider using Loofah directly (that's what handles sanitization under
the hood).
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'

slim-rails gem crush on start `register_config_processor': wrong number of arguments

when I'm adding slim-rails to Gemfile and starting my app, it crashes with such error:
/Users/rado/.rbenv/versions/2.3.1/gemsets/project/gems/sprockets-4.0.0.beta2/lib/sprockets/processing.rb:211:in `register_config_processor': wrong number of arguments (given 4, expected 2..3) (ArgumentError)
from /Users/rado/.rbenv/versions/2.3.1/gemsets/project/gems/sprockets-4.0.0.beta2/lib/sprockets/processing.rb:53:in `register_preprocessor'
from /Users/rado/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/slim-rails-3.1.1/lib/slim-rails/register_engine.rb:33:in `block in _register_engine'
from /Users/rado/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:178:in `block in build_environment'
from /Users/rado/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:177:in `each'
from /Users/rado/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:177:in `build_environment'
My rails version is 5.0.0.1
Anybody knows how to fix this?
Works if the gem is plugged in directly from GitHub:
gem 'slim-rails', github: 'slim-template/slim-rails'
Problem addressed: incompatibility of gem 'slim-rails' with Sprockets 4. (If you're using Rails 5 but Sprockets 3, this solution may not help.)
The slim-rails team have solved it in this commit, but for me it still crashes when I plug the gem from rubygems.org — but works well when using the GitHub version.

Undefined method 'register_engine' while trying to install Ember to Rails

I started learning Ember.js using Rails as back-end, and created a test project. So, first I removed turbolinks from app and added the following gems to Gemfile:
gem 'ember-rails'
gem 'ember-source', '~> 1.8.1'
gem 'emblem-rails'
and bundled them. Next, I ran
$ rails g ember:bootstrap -n App --javascript-engine js
and it has returned me the following error:
/home/alex/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/emblem-rails-0.2.2/lib/emblem/rails/engine.rb:7:in
`block in <class:Engine>':
undefined method `register_engine' for nil:NilClass (NoMethodError)
Is the problem that something can be deprecated? I'm following the tutorial written in 2014.
The trouble was caused by emblem-rails gem - I commented it out, and everything worked

undefined method 'configure' inside the initializer? added a new ruby gem

I installed the gem Bitly into my rails app
I did it by running gem install bitly
then I manually added gem 'bitly' into my gemfile
I created this inside `config\initializers\bitly.rb
Bitly.configure do |config|
config.api_version = 3
config.login = "myusername"
config.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
end
I'm trying to get my rails server running but I get this error I've never seen before
Exiting
C:/app/config/initializers/bitly.rb:1:in `<top (
required)>': undefined method `configure' for Bitly:Module (NoMethodError)
How can I resolve this issue and make this gem work?
I am trying to use the gem inside one of my models
bitly.shorten("http://mydomain.com/article/#{id}")
Bitly is currently available in version 0.8.1 on rubygems. This version does not support Bitly.configure. I recomend you use the gem from github, until someone releases a newer version on rubygems.
The bitly line in your Gemfile should look like this:
gem "bitly", :git => 'https://github.com/philnash/bitly/'
Then do a bundle install and bitly should work the way you expect.
Edit: There is even a github issue for that error :)

Resources