undefined method `escape' for URI:Module in ruby 3 - paperclip

After updating my Rails application from Rails 6.0.1 to Rails 7.0.2.3
I am getting issue with the gem "paperclip", '~> 6.1.0'
while using it in application is gives error:
ActionView::Template::Error (undefined method `escape' for URI:Module
Did you mean? escape_once):
Usage in my application:
<%= image_tag current_user.image.url('med'), width: "36px" %>
How to resolve this issue when bug is present in the ruby gemfile itself, thanks in advance.

The solution to this situation do a monkey patching to the missing method in library.
add a ruby filke uri_escape.rb inside the initializers folder:
add lines for monkey patching:
module URI
def URI.escape(url)
url
end
end
and its done.

Related

Rails legacy app and Ruby 2 error: can not load translations from the file type yml is not known

I have a legacy Rails application which I want to upgrade to recent Rails and Ruby versions.To start with I am trying to setup the application with Ruby 2.1.2
$ rails -v
Rails 2.3.18
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i686-linux]
When I tried to run the rake task rake db:schema:load RAILS_ENV=test I encountered following error
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
Searching through Google I found the following reference https://github.com/rails/rails/issues/10514 which mentioned that there is incompatibility between Rails 2.3 and Ruby 2+ versions.
Can anybody please help me applying a monkey-patch mentioned about in the reference link?
Thanks,
Jignesh
Finally resolved the error
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
by monkey-patching the Rails’s I18n::Backend::Base#load_file(filename) method.
The solution is as follows:
1.1 Created a file named ruby2.rb at /config/initializers
1.2 Added following contents to /config/initializers/ruby2.rb
if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0'
module I18n
module Backend
module Base
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
# As a fix added second argument as true to respond_to? method
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true)
data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
data.each { |locale, d| store_translations(locale, d) }
end
end
end
end
end
1.3 Finally ran
$ rake db:schema:load RAILS_ENV=test
and the schema was successfully loaded.
Most helpful references I could find and which helped me get to the solution:
https://github.com/rails/rails/issues/10514
https://www.lucascaton.com.br/2014/02/28/have-a-rails-2-app-you-can-run-it-on-the-newest-ruby/

uninitialized constant Moped::BSON in rails 4 app on heroku

I just updated from rails 3 to rails 4. Everything works locally, but deployed on heroku, I get the following error:
ActionView::Template::Error (uninitialized constant Moped::BSON):
3: %nav.navbar-collapse
4: %ul.nav
5: %li
6: - if user_signed_in?
7: = link_to 'Logout', destroy_user_session_path, :method=>'delete'
8: - else
9: = link_to 'Login', new_user_session_path
app/views/layouts/_navigation.html.haml:6:in `_app_views_layouts__navigation_html_haml___1118031947301940708_70104067139880'
app/views/layouts/application.html.haml:18:in `_app_views_layouts_application_html_haml__1093647294459268715_70104069850820'
The same error occurs in other haml files when I access current_user
- if current_user
...
The following worked for me:
add to Gemfile:
gem "bson"
gem "moped", github: "mongoid/moped"
bundle install
add to application.rb:
require "bson"
require "moped"
Moped::BSON = BSON
Answer from:
https://github.com/mongoid/mongoid/issues/3455
See this comment from Moped's author as of Moped 2.0.0 (which is the version , as of this writing, used as the driver in mongoid 4.0.0):
Moped's BSON implementation has been removed in favor of the 10gen bson gem 2.0 and higher. All Moped::BSON references should be changed to just BSON.
https://github.com/mongoid/moped/blob/master/CHANGELOG.md
This error can also be caused by having references to Moped::BSON in serialized cookies/session. Deleting cookies fixes it then.

will_paginate helper undefined in sinatra with mongoid

I am using sinatra 1.4.3 and mongoid 3.1.4. I tried adding will_paginate gem from master branch for mongoid support so I added this to my gemfile:
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git',
:branch => 'master'
In environment.rb I added:
require 'will_paginate'
require 'will_paginate/mongoid'
And pagination method started working. I have still problem with will_paginate helper. In my views I get errors like:
NoMethodError: undefined method `will_paginate' for #<Class:0x006ff5df8578b0>
Am I missing something for helper to work under sinatra?
I don't know if it's best solution but adding
include WillPaginate::Sinatra::Helpers
in my controller solved my problems.

undefined method `action_mailer' with Ruby 1.9.2 and Rails 3.0.8

The full error is:
/Users/me/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/railtie/configuration.rb:77:in `method_missing': undefined method `action_mailer' for #<Rails::Application::Configuration:0x00000102f545f8> (NoMethodError)
I've searched several variations of this error and come up empty.
Thanks.
Probably you're requiring only specific parts from rails in you application.rb (i.e., not using require rails/all). Try putting require "rails/all" in there.
i uninstalled rails 3.0.8 files and then reinstalled rails 3.0.8 and that fixed the problem.

Rails 3 Authlogic - 'acts_as_authentic' undefined

I'm getting the following error:
NameError (undefined local variable or method `acts_as_authentic' for #<Class:0x1037e6310>):
app/models/user.rb:2
app/controllers/user_controller.rb:3:in `new'
I'm using Rails 3.0.0, with Ruby 1.8.7. Authlogic is in my Gemfile as follows:
gem 'authlogic', :git => "git://github.com/binarylogic/authlogic.git"
The entire contents of my User.rb file are as follows:
class User < ActiveRecord::Base
acts_as_authentic
end
I get the same error whether through 'rails console' or through the server. I have restarted the server more times than I can count. Please help, I can't figure it out.
Use a version of authlogic patched for Rails 3
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
Or even better. Use Devise
Is the Authlogic Gem installed ?.
Please do
Bundle install
this should solve your problem.
gem "authlogic", "2.1.6"
Then
Bundle install
Hope it'll helpfull for you. :)
create a file in config/initializers as restful_authentication.rb
and paste this inside the file and restart server and try
require 'authenticated_system'
require 'restful_authentication/authentication'
require 'restful_authentication/authentication/by_password'
require 'restful_authentication/authentication/by_cookie_token'
require 'restful_authentication/authorization/aasm_roles'
require 'restful_authentication/authorization/stateful_roles'
require 'restful_authentication/trustification/email_validation'

Resources