style option breaking paperclip - paperclip

In my gemfile i have gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
and gem "cocaine", "~> 0.5.1" (Other questions that report cocaine broke paperclip have been fixed in this version)
In my model has_attached_file :photo , :styles => { :thumb => "32x32#" }
In my development.rb Paperclip.options[:command_path] = "/user/local/bin"
I get an Photo Paperclip::Errors::NotIdentifiedByImageMagickError error when I try and upload.
If however I change my model to has_attached_file :photo removing the style attribute everything works fine. I need to be able to resize my images though, why is the style attribute breaking my uploads?

Looks like you don't have ImageMagick installed.
When paperclip tries to create a thumbnail, it needs ImageMagick to resize the image. Without the :styles, paperclip just saves the original image and ImageMagick is not needed.

Related

Upload Facebook profile image with Carrierwave

I'm trying to use the Facebook profile image with Devise, uploading it to S3 with CarrierWave / fog, but the link I'm getting from Facebook provided in auth.info.image is a link to download the file, not an image that CarrierWave can use.
If you go to the link in a browser, it is a file download link. I've not seen any articles anywhere that address this. I thought I could use CarrierWave to download the file to /tmp, then upload it, but calls to CarrierWave::Uploader::Download do not work. Or I've seen other articles explaining that you can save the link provided by Facebook just use that in an = image_tag but that doesn't work, either.
In my User model:
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create! do |user|
user.email = auth.info.email
user.provider = auth.provider
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.uid = auth.uid
user.password = Devise.friendly_token[0, 20]
user.password_confirmation = user.password
user.profile_image = auth.info.image
end
end
but user.profile_image is nil. I have no problem with CarrierWave - I've used it on several other projects to save to AWS with fog.
I would like to either a) save a link to the image that I can use in a Rails view, but as mentioned already, I do not have that - the link returned by Facebook is a link to download an image, so, b) is to download the file, save the filename to the User model and upload the file to AWS.
Use "#{auth.info.image}?type=large" instead of auth.info.image
Apparently CarrierWave has its own magic, whereby if you prepend the field name with remote_ and append it with _url it knows to download a file before uploading. So, my field name is profile_image, and (in my User model) self.from_omniauth(auth) method:
user.remote_profile_image_url = auth.info.image
just works. The field name has the correct filename saved to it, and the files (full size and thumbnail) are uploaded to S3.

How can I upload paperclip image on remote server (accessed by pem file) rails console?

I am having production server and database is from aws. I visit remote machine using pem file & start rails console.
I have particular invitee (from Invitee model) & have following column to store image using paperclip
invitee.rb
has_attached_file :profile_pic, {:styles => {:large => "640x640>",
:small => "200x200>",
:thumb => "60x60>"},
:convert_options => {:large => "-strip -quality 90",
:small => "-strip -quality 80",
:thumb => "-strip -quality 80"}
}.merge(INVITEE_IMAGE_PATH)
I want to upload image at https://imgur.com/9a6UzVx by using rails console production. How can I do this?
Input I can have is, image url and object of invitee for which profile_pic columns to be updated.
I have image in my local machine but I cannot upload it from local to remote so using https://imglur.com
I suggest you to check another answer "Save image from URL by paperclip
" which does what you want to achieve. Check code snippet: self.profile_pic = open(url) will upload the picture to your model. Your picture real URL is https://i.imgur.com/9a6UzVx.png

How to upload video to YouTube via Ruby?

I need to upload video files from my computer to youtube automatically, I use ruby.
I tried gem youtube_it - I have error YouTubeIt::AuthenticationError: BadAuthentication - my actions:
client = YouTubeIt::Client.new(:username => "email#gmail.com", :password => "my_passwd", :dev_key => "developer_key")
client.video_upload(File.open("file_from_drive"), :title => "test",:description => 'test')
Also I tested manually upload video from my email#gmail.com my_passwd Google account - I works well. Dev_key I got here - http://code.google.com/apis/youtube/dashboard
Then I tried gem gdata as here - How to upload video on YouTube with Ruby
require 'gdata'
yt = GData::Client::YouTube.new
yt.clientlogin("email#gmail.com", "my_passwd")
It raises error
GData::Client::AuthorizationError: request error 403: Error=BadAuthentication
Info=WebLoginRequired
So, How should I automatically upload video? Maybe problem is in my google account?

Selenium can't find fields with type number

I'm having a problem getting Cucumber to find fields with the HTML5 type="number". I'm not a big fan of the way they look in the browser, but I have a few fields that need the number keyboard on mobile, and this seems to be the easiest way to get it. I'm using SimpleForm to build forms and when I set :as => :text everything works, but if I set :as => :number, the fields don't get filled out. I don't get any error, the field just doesn't get filled.
To be specific, when I have a step like this:
And I fill in "application_form_age" with "52"
then this tag won't get filled in:
<input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">​
but this one works:
<input class=​"string required" id=​"application_form_age" name=​"application_form[age]​" size=​"50" type=​"text">​
Also, it only happens in #javascript scenarios. In situations where #javascript isn't necessary and the scenario doesn't launch a browser, that works fine too.
Versions of things:
capybara (2.2.1)
cucumber (1.3.14)
selenium-webdriver (2.41.0)
simple_form (2.1.1)
webrat (0.7.3)
Firefox 29.0
I'm stumped. I tried yanking out a bunch of my application JS and CSS to see if something I'm doing is breaking it, but no luck with that. I'm just patching it out by forcing those fields not to have HTML5 type number in my test environment, but I don't want to live like that. Is anyone else seeing this? I haven't been able to find any references to it, which makes it seem like it's something I'm doing. But I haven't been able to figure it out.
Ok, I have found firefox has an option to disable number input field support: 'dom.forms.number'.
So if you add the following lines in your env.rb, number input gets disabled and tests work again.
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.forms.number"] = false
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
First off, I think you have some confusion regarding those frameworks. Cucumber is a BDD framework, which doesn't automate browsers in any way, so this question has nothing to do with it (This is why I removed it from your question title).
Looks like you are using Capybara, which is an ATDD framework. You might probably consider showing us the Capybara code you use in order diagnose your problem.
Under the hood, I assume you use Selenium WebDriver, I can confirm that Selenium works fine with <input type="number"> (Tested with Firefox 28, which is the one selenium-webdriver (2.41.0) supports to).
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
DEMO_PAGE = <<-eos
data:text/html,
<input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">
eos
driver.get(DEMO_PAGE)
driver.find_element(:tag_name, 'input').send_keys('25')
So you might want to create a similar demo using Capybara to test this functionality.
If the demo works, then we need take a closer look at your application.
Othwewise, please raise a ticket for Capybara developers.

Issues with link on Watir and Safari?

I am new in using watir but I can only imagine this to be a bug:
require "watir"
Watir::Browser.default = 'safari'
b = Watir::Browser.new
b.goto()
=> nil
b.link(:title, "Start").click
Leads me to the next page as expected but on the following page no link works even they are there
b.link(:title, "Do something").exist?
=> true
When I then enter
b.link(:title, "Do something").click
nothing happens, even the href attribute of course links to the next page (to be more precise, it is the same page but different request parameters)
Identifying the link with :xpath looks similar.
The same thing works fine with "firefox" as browser.
I use Safari 5.0.1, ruby 1.8.7 and installed beside others safariwatir-0.3.8
In fact controlling safari partially works but I have no glue why it hangs on the second page. Here is an example using a scenario in the internet:
this works fine:
browser.goto("http://reiseauskunft.bahn.de/bin/query.exe/dn?S=Frankfurt(Main)Hbf&Z=Nrnberg%20Hbf&date=%2B30&time=1500&start=1&")
=> nil
this also works fine - the link does exist:
browser.link(:title, /Mit Tickets zum Normalpreis/).exist?
=> true
this does not work - the browser window stays unchanged:
browser.link(:title, /Mit Tickets zum Normalpreis/).click
=> nil
I would like to try fire_event or fireEvent but irb says invalid method. I guess the hints I found about firing an event are outdated?
As far as I know, the only way to drive Safari is to use safariwatir gem (works only on Mac OS X). Try this (from SafariWatir wiki page at Watir wiki):
require 'rubygems'
require 'safariwatir'
browser = Watir::Safari.new
browser.goto("http://google.com")

Resources