Rails 4.2 will_paginate error - ruby-on-rails

Trying to upgrade to Rails 4.2 from 4.1.8 and I'm getting a "wrong number of arguments (2 for 0..1)" for this line:
<%= will_paginate(#search) %>
Works perfectly find in Rails 4.1.8. #search is a custom object which defines the methods will_paginate needs (total_pages, etc).
The method signature for will_paginate is:
def will_paginate(collection = nil, options = {}) #:nodoc:
And I verified the proper method is being called by using:
<%= self.method(:will_paginate).source_location %>
Which outputted:
["/Users/home/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/will_paginate-3.0.7/lib/will_paginate/view_helpers/action_view.rb", 26]
Kind of stumped, and surprised that nobody else has encountered this issue.

Turns out the bartt-ssl_requirement gem overrides :url_for in a way that is not compatible with Rails 4.2. Removing that gem resolved the issue.

Related

How to fix Kaminari paginate error in view?

When I use Kaminari gem with the code:
Model:
def index
#posts = Post.page(params[:page])
end
And use it in index.html.erb:
It prints the next error:
undefined method `paginate' for #<#<Class:0x000000029bbd68>:0x000000029b3dc0>
red line on <%= paginate #posts %>.
How can I fix this problem? Is my #posts paginable? I think yes.
If it's in the Gemfile, then you just need to run bundle install instead of gem install Kaminari. I would then restart my rails server to ensure its initializers are run to properly require its files.

Rails 4.1.4 ActionView::Base Default Form Builder Doesn't Exist

Using Ruby 2.1.1 Rails 4.1.4
Hi,
I've been banging my head on a really strange issue I'm seeing with FormHelper. I'm simply trying to build a form using form_for and I'm getting the cannot call new for nil class error when the view tries to render. Through the backtrace, I found that the issue is actually in:
ActionView::Helpers::FormHelper#instantiate_builder:1145-1146
builder = options[:builder] || default_form_builder
builder.new(object_name, object, self, options)
default_form_builder is defined as follows in ActionView::Helpers::FormHelper
def default_form_builder
builder = ActionView::Base.default_form_builder
builder.respond_to?(:constantize) ? builder.constantize : builder
end
I have not added a Custom Form Builder and am simply trying to use the default. When I check what ActionView::Base.default_form_builder is, I get nil.
The 2 solutions to get it to work for me were:
Pass a Form Builder Object to the form_for options[:builder] hash
Add the following line in my environment config
config.action_view.default_form_builder = ActionView::Helpers::FormBuilder
I'm using 2) for now but both of these shouldn't be necessary.
I've looked everywhere but no luck with what is going on. Thanks for any help!
Did you have gem 'extlib' and gem 'devise' in Gemfile?
Move gem 'extlib' line under gem 'devise' line.
I don't know why but it will work...

Need To Add Locale To link_to Statement in a Mailer View

I have removed gem routing-filter from my Rails 3.2.13 application in preparation to upgrade it to Rails 4. The author(s) have a beta version for Rails 4 but I could never get it to work. I have implemented the normal Rails process for localization/internationalization. The last issue I need to resolve is a link_to statement that displays a thread in a mailer view.
When I was using routing-filter I had the link_to statement as below where I set #host in my mailer depending on the environment.
<%= link_to "#{t :view_thread}", micropost_url(#item), host: "#{#host}" %>
When I uninstalled routing-filter I started getting errors because of a missing locale when the attempt is made to send the email. It crashes and sends the application back to the landing page. The gem took care of this.
I have been searching for about an hour trying to find the correct syntax for this but I'm not finding any examples that include both the host and locale parameters. I have tried several guesses but I get syntax errors.
Any help would be appreciated. I will keep searching and trying.
Here is the solution I came up with. I was not sure where the locale clause should go related to the host clause. I decided to try the statement below and it worked.
<%= link_to "#{t :view_thread}", micropost_url(#item, locale: I18n.locale.to_s), host: "#{#host}" %>
Updated solution for Rails 6 (and probably 5).
First, make sure you followed Rails guides on localization, so it's all set up
Then, add this to your ApplicationMailer:
def default_url_options(options = {})
ActionMailer::Base.default_url_options
.merge(locale: I18n.locale)
.merge(options)
end
This will use your selected locale for links generation, so you don't have to pass locale: #locale every time.
And then, set current locale in your mailers with the following block.
I18n.with_locale(#locale) do
mail(to: #email,
subject: I18n.t("mailers.my_mailer.subject"))
end
The last piece of advice - don't forget to fallback with your #locale var, so it's smth along these lines: #locale = #user.locale || I18n.default_locale
Update:
Or you can simply monkeypatch mail method, but make sure you know what you're doing.
def mail(**)
I18n.with_locale(#locale || I18n.default_locale) { super }
end

undefined method `html_safe' for #<String:0x1042222c0> using recaptcha

I'm getting this error on the line where I call recaptcha_tags
<%= recaptcha_tags( :public_key => 'XXXXXXYYYYYYYZZZ-ZXYXXZYZ' , :display=>{:theme=>"white" }) %>
I'm working with rails 2.3.10
how can I solve this error?
many thanks.
In Rails 2.3.x, html_safe is defined as a String class method in:
activesupport/lib/active_support/core_ext/string/output_safety.rb
Make sure that you have the proper active_support version (one matching your rails version).
Well i did what's specified here https://github.com/ambethia/recaptcha/issues/30 and worked out perfectly for me
Changing client_helper.rb line 39 to:
return (html.respond_to?(:html_safe) && html.html_safe) || html
fixes the issue.

RoR rendering images inline rails 2.3.8

I'm trying to render an image inline in an email, and my rails app is version 2.3.8.
Can someone provide me with an example of how to do this? Here's what I got so far, but I keep getting errors.
Here's my method:
def notice(contact)
subject 'notice'
recipients contact.email
from 'something.com'
sent_on Time.now
attachments.inline['paypal_seal.gif'] = File.read('/images/paypal_seal.gif')
body :contact => contact
end
And in the view:
<%= image_tag attachments['paypal_seal.gif'].url %>
This is the error I get:
undefined local variable or method `attachments' for #<ContractorNotifier:0x61413c8>
Thank you
What you are trying to do is the 'Rails 3' way of handling attachments. If you are starting out, I highly recommend upgrading to Rails 3. Otherwise, try an older 2.3 guide like:
http://blog.thoughtobject.com/2007/05/26/5/

Resources