Rails undefined method `query=' for #<HTTPI::Request:0x007f914b61f8d0> - ruby-on-rails

I am trying to integrate a Rails App with ActiveCampaign CRM using the following gem: https://github.com/RushPlay/active_campaign
ac = ActiveCampaign::Client.new({:api_method => 'https://website.api-us1.com',:api_key => 'mykey'})
response = ac.contact_sync({ :email => "test#test.com",:first_name => "John",:last_name => "Doe" })
The request is unsuccessful and Rails returns this:
undefined method `query=' for #<HTTPI::Request:0x007f914b61f8d0>
Any idea why this might be? I've been trying to figure it out for a while, and can't get to the bottom of it...
UPDATE
I tried updating my HTTPI gem to a newer version (2+) and the original error disappeared, but now I am seeing the following error:
757: unexpected token at '<div align="center">
<div style="font-size:15px; color:#333; padding: 50px; font-family:Arial, Helvetica, sans-serif;">
<div style="font-size:33px; padding:12px;">Not Found</div>
<div>Sorry, this page could not be found.<br />
Please check your link/URL and try again.</div>
</div>
</div>'
Any ideas?

active_campaign's gemspec doesn't specify a httpi version, looking at the commit that added the query= method, it looks like it's been in there since 2.0.
Do you have an old (1.x) version of httpi in your Gemfile.lock? If you bundle up httpi, does it help?

Related

Upgrading to Rails 5 ActionView::Template::Error: no implicit conversion of Hash into String with image_tag

I'm upgrading from rails 4.2 to rails 5.1.1 and I have this strange breaking change in my email views.
I've enabled ApplicationMailer and made my WelcomeMailer inherit from it, but I haven't changed anything else and I'm getting this error in Sidekiq when I try to send any email. This has always worked fine in Rails 4. I've tried rewriting the url and removing the #ref. Ref is not an object, it is a string calculated like
#ref = "#{variable_1}&#{variable_2}"
Here is the action view error:
ActionView::Template::Error: no implicit conversion of Hash into String
It highlights both
= link_to email_links_url(link_label: 'root', ref: #ref ), target:"_blank"
= image_tag "#{Rails.configuration.adjusted_image_path}branding/our-logo-mail.jpg", style: "width: 150px; margin-left: auto; margin-right: auto", alt: "SomeCompany Name"
development.rb
config.adjusted_image_path = ""

Rails 4.2 upgrade: Asset names passed to helpers should not include the "/assets/" prefix

I upgraded from Rails 4.1 to 4.2. I get the following error now:
Sprockets::Rails::Helper::AbsoluteAssetPathError at /
Asset names passed to helpers should not include the "/assets/" prefix. Instead of "/assets/spinner.gif", use "spinner.gif"
The error message is clear. However, I don't know what it's talking about. It highlights this line of code:
<div class="loading">
<%= image_tag asset_path('spinner.gif') %>
</div>
I do not use the literal string '/assets/' in that line of code. So what is this error referring to?
I was able to resolve that specific error by removing the call to asset_path and just using image_tag 'spinner.gif'; however, I still get the error right here (I am using Paperclip gem):
<%= image_tag current_user.avatar.url(:thumb) %>
caused by this:
ActionController::Base.helpers.asset_path('missing-user.png')
Again, it is complaining about asset_path.
UPDATE:
Error only occurs when I pass asset_path to image_tag method:
ActionController::Base.helpers.asset_path('missing-user.png')
=> "/assets/missing-user.png"
helper.image_tag(ActionController::Base.helpers.asset_path('missing-user.png'))
Sprockets::Rails::Helper::AbsoluteAssetPathError: Asset names passed to helpers should not include the "/assets/" prefix. Instead of "/assets/missing-user.png", use "missing-user.png"
image_tag will pass the source option to asset_path on its own:
image_tag("icon")
# => <img alt="Icon" src="/assets/icon" />
image_tag("icon.png")
# => <img alt="Icon" src="/assets/icon.png" />
image_tag("/icons/icon.gif", height: '32', width: '32')
# => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
So when you call image_tag asset_path('spinner.gif') you're actually doing image_tag( '/assets/spinner.gif' ) which is why you get the sprockets warning.
I resolved the issue but I still don't understand the WHY factor. This only happens when I upgraded from Rails 4.1 to 4.2. Check this out:
ActionController::Base.helpers.asset_path('missing-user.png')
=> "/assets/missing-user.png"
helper.image_tag "/assets/missing-user.png"
Sprockets::Rails::Helper::AbsoluteAssetPathError: Asset names passed to helpers should not include the "/assets/" prefix. Instead of "/assets/missing-user.png", use "missing-user.png"
helper.image_tag "missing-user.png"
=> "<img src=\"/assets/missing-user.png\" alt=\"Missing user\" />"
Based on the above, image_tag does not want you to pass it the literal path string 'assets'. Consequently, in my Paperclip gem helper, I had to od this:
has_attached_file :avatar,
styles: { normal: "128x128>", thumb: "40x40>" },
default_style: :thumb,
default_url: ->(attachment) { 'missing-user.png' }
In other words, I had to remove this:
ActionController::Base.helpers.image_url('missing-user.png')
since image_url returns the string '/assets/missing-user.png'.

Passing params to iframe in rails not working

I'm a rails noob so I know I'm probably totally missing something here. I'm trying to pass a url to an iframe through my products controller.
This is my setup.
Products Controller
def open_url
#url = params[:url]
end
index.html.erb
<%= link_to "More Info", open_path(url: "http://www.ceratoboutique.com" + product.destination_url) %>
open_url.html.erb
<iframe src= "<%= #url %>" style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%" />
routes.rb
get '/open' => 'products#open_url', via: 'get'
I,ve checked out these two questions
Rails 4 - Passing Params via link_to?
Opening a Link in a New Window within an iFrame
but i'm still lost, the url is passed to the browser but it does not seem to pass to the #url variable in my controller.
Debug Dump
!ruby/hash:ActionController::Parameters
url: http://www.ceratoboutique.com/collections/tops/products/combo-blouse
controller: products
action: open_url
I decided to stick to rails conventions and make it a restful link. I still do not know why the original implementations did not work, but it worked using the show method in the controller.
Controller
def show
#url = Product.find(params[:id])
end
index.html.erb
<%= link_to "More Info", product_path(product) %>
show.html.erb
<iframe src= "<%= "http://www.ceratoboutique.com" + #product.destination_url %>" style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%" />
****Edit Added More Info for including I-Frame ****
I ran into a lot of problems trying to get my iframe to work in chrome and on Heroku so I combined the process if anyone needs it ever. I first deployed to Heroku with full SSL running on my site, then realized that iframe did not work in chrome for sites that were not running SSL. I redeployed configuring force SSL to false, but heroku still forced my app to SSL. I realized that config.force_ssl = true enables Strict Transport Security header(HSTS) with max-age of one year, so I had to expire HSTS using the following.
Expire SSL in application controller
class ApplicationController < ActionController::Base
before_filter :expire_hsts
def expire_hsts
response.headers["Strict-Transport-Security"] = 'max-age=0'
end
In Production.rb
config.force_ssl = false
Then to make sure the x-frame showed in chrome browsers I added the following.
enable x-frame in chrome
config.action_dispatch.default_headers = { 'X-Frame-Options' => 'ALLOWALL' }
You may want to run SSL on some of your pages, which can be done rather easily via the SSL enforcer gem linked below.
ssl-enforcer gem
https://github.com/tobmatth/rack-ssl-enforcer
Best of luck on navigating the ugliness that is the iFrame!

Omniauth facebook - fetch friends

I am trying to configure omniauth-facebook to fetch user friends.
This is my configuration:
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :facebook, "xxxxxx", "xxxxxxxx",
:info_fields => 'friends'
end
I am using Rails 2.3.
I am using this code in view:
<div id="contacts">
</div>
<script type="text/javascript" charset="utf-8">
$('contacts').innerHTML = '<%= request.env['omniauth.auth'].keys %>';
</script>
I am not sure why the script is not being executed, but when I copy:
$('contacts').innerHTML = 'infouidcredentialsextraprovider';
in console after page has loaded it works replacing content of div with that text.
There is no error message in browser console.
Why script does not get executed? I tried with console.log too, and I had no luck.
The info_fields option is still new and so you will have to wait for a new release of the omniauth-facebook gem.
In the meantime, you can try using the master branch by changing your Gemfile to:
gem 'omniauth-facebook', :github => 'mkdynamic/omniauth-facebook'
As for debugging, you can get the information returned from facebook by adding the following as the first line of your callback controller:
raise request.env["omniauth.auth"].to_yaml
Now try to login and you'll be able to take a good look at the hash of nested hashes returned.

Extra whitespace when rendering a text_area in Rails 3.2.3

I'm getting an extra white space inside the text area when rendering this HAML code.
= f.text_area :message, placeholder: "Reply"
I'm running Rails 3.2.3 and haml-rails 0.3.4 and haml 3.1.4
I have no idea why this is happening.
This is the code rendered with the extra whitespace
<textarea class="textarea" cols="50" id="idea_idea" name="idea[idea]" rows="2">
</textarea>
Just found a solution to this problem.
I upgraded to the "3.1.5" beta version of HAML and works fine now.
gem 'haml', :git => "git://github.com/haml/haml.git", :branch => "315"
The version you are running should have similar issues fixed, see the ActionPack Changelog linked below, it appears to contain multiple entries related to the issue.
https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md

Resources