What is the difference between:
cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
and
cookies[:login] = { :value => "XJ-122", :expires => 1.hour }
Aren't both times calculated at the time the cookie is set, and therefore 'from_now' is irrelevant?
You can always check your understanding using "rails console".
$ rails c
Loading development environment (Rails 3.2.3)
1.9.2-p318 :001 > 1.hour
=> 3600 seconds
1.9.2-p318 :002 > 1.hour.class
=> Fixnum
1.9.2-p318 :003 > 1.hour.from_now
=> Fri, 25 May 2012 04:16:57 UTC +00:00
1.9.2-p318 :004 > 1.hour.from_now.class
=> ActiveSupport::TimeWithZone
ActiveSupport::TimeWithZone is a 'glorified' Time class.
:expires needs a Time instance. So, you should use 1.hour.from_now
Related
I currently have an application using paperclip that allows users to upload their creatives. This has worked flawless thus far when it comes to a user uploading an image file. We have since tested to upload a .mov file and I get this error:
Creative Paperclip::Errors::NotIdentifiedByImageMagickError
The weird thing, this error is only generated on Heroku. I can upload .mov files just fine on my local host.
My Current Gem Setup:
paperclip (3.4.1, 3.4.0)
paperclip-aws (1.6.7, 1.6.6)
paperclip-ffmpeg (0.10.2)
cocaine (0.5.1, 0.4.2)
Event.rb
has_attached_file :creative,
:processors => [:ffmpeg],
:styles => {
:thumb => [:geometry => "250x150", :format => 'png'],
:custcreative => [:geometry => "275x75", :format => 'png'],
:creativepreview => ["275x195",:png]
},
:url => "***",
:path => "***",
:s3_domain_url => "***",
:storage => :s3,
:s3_credentials => Rails.root.join("config/s3.yml"),
:bucket => '***',
:s3_permissions => :public_read,
:s3_protocol => "http",
:convert_options => { :all => "-auto-orient" },
:encode => 'utf8'
Spending hours trying to figure out why this works locally but throwing error on Heroku.
I even tried removing the :style setting, but still did not work.
TIA
EDIT
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/MidPen20130413-2-1mzetus.mov[0]'
Well, here is the answer in case any other newbies like us come across the same problem. The issue is with the geometry method that is being used for image cropping. The way it is suggested in railscasts assumes the file is in a local system and that needs to be changed.
OLD METHOD:
def avatar_geometry(style = :original)
#geometry ||= {}
#geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))
end
NEW METHOD
def avatar_geometry(style = :original)
#geometry ||= {}
avatar_path = (avatar.options[:storage] == :s3) ? avatar.url(style) : avatar.path(style)
#geometry[style] ||= Paperclip::Geometry.from_file(avatar_path)
end
For some reason I'm not getting any emails from ExceptionNotifier. I followed the instructions here https://stackoverflow.com/a/4818532/766953.
I did this test:
so#plike:~/proj$ bundle exec rake middleware | grep ExceptionNotifier
so#plike:~/proj$ use ExceptionNotifier
And see this in the server logs:
Sent mail to stackOverlord#yahoo.com (53ms)
Date: Tue, 31 Jan 2012 18:48:57 -0800
...
I've never sent email from my rails app before, is there any anything I'm missing? Also how does it magically send from whatever email address I specify?
Nvm had to add this to my environments/development.rb and enviroments/production.rb
SampleApp::Application.configure do
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'stackoverlord.com',
:authentication => :plain,
:user_name => 'mygmailusername#gmail.com',
:password => 'mygmailpassword'
}
end
I am currently using the following options in my Rails app to enable HTTPS with WEBrick:
{
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("certificates/https/key.pem").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("certificates/https/cert.pem").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
}
How would I go about specifying an intermediate certificate?
I managed to find an answer after an extra hour of googling for keywords. Here is the option to define an intermediate certificate:
:SSLExtraChainCert => [
OpenSSL::X509::Certificate.new(
File.open("certificates/intermediate.crt").read)]
Note that the option requires an Array object, allowing to you include multiple certificates if needed.
If you are using rails 3, then modify the script/rails file as
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rubygems' # if ruby 1.8.7
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("/key/vhost1.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("/crt/vhost1.crt").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
})
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
The above code was modified from the example in Configuring WEBrick to use SSL in Rails 3. This worked for me.
I'm using postgresql in development for the first time and have successfully installed the binary onto my 10.6 machine. I've created a Rails superuser, createdb => 'vitae_development' with this user. It shows up in $pqsl => '/du', but when I key in /dt, I get 'no relations'.
My pg gem is pg-0.12.0
In rails 3.10 console, I enter: User.create!(:name => "Sam", :email => "sam#email.me")
The resulting output is:
INSERT INTO "users" ("created_at", "email", "name", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", Wed, 21 Dec 2011 19:40:13 UTC +00:00], ["email", nil], ["name", nil], ["updated_at", Wed, 21 Dec 2011 19:40:13 UTC +00:00]]
That appears to be a bunch of blanks. I've searched the googles but must have missed the right search terms.
pgAdmin3 seems to show the tables in place, as best as I can determine, but with no data that I can find.
This is the relevant snippet from my database.yml:
development:
adapter: postgresql
database: vitae_development
username: rails
password:
pool: 5
timeout: 5000
For completeness, here's the whole user.rb:
class User < ActiveRecord::Base
attr_accessor :name, :email
email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_insensitive => false }
end
What am I overlooking? I've done rake db:migrate.
Did you perhaps override the email or email= methods or put attr_accessor :email in your User.rb file?
EDIT:
Take out line 2 where it says attr_accessor :name, :email. attr_accessor in the context of rails is for object variables that won't be saved to the database.
Try eliminating the formatting validation on email...if it works I'd take a deeper look at email_regex
I have Rails 3.0.3 with these gems:
delayed_job 2.1.4
delayed_paperclip 0.7.1
paperclip 2.3.16
paperclip-ffmpeg 0.7.0
(This combination is very specific. Some newer gems will not work with others.)
Here's my Video model:
class Video < Upload
has_attached_file :file, :default_style => :view, :processors => [:ffmpeg],
:url => '/system/:class/:attachment/:id/:style/:basename.:extension',
:path => ':rails_root/public/system/:class/:attachment/:id/:style' \
+ '/:basename.:extension',
:default_url => '/images/en/processing.png',
:styles => {
:mp4video => { :geometry => '520x390', :format => 'mp4',
:convert_options => { :output => { :vcodec => 'libx264',
:vpre => 'ipod640', :b => '250k', :bt => '50k',
:acodec => 'libfaac', :ab => '56k', :ac => 2 } } },
:oggvideo => { :geometry => '520x390', :format => 'ogg',
:convert_options => { :output => { :vcodec => 'libtheora',
:b => '250k', :bt => '50k', :acodec => 'libvorbis',
:ab => '56k', :ac => 2 } } },
:view => { :geometry => '520x390', :format => 'jpg', :time => 1 },
:preview => { :geometry => '160x120', :format => 'jpg', :time => 1 }
}
validates_attachment_content_type :file, :content_type => VIDEOTYPES,
:if => Proc.new { |upload| upload.file.file? }
process_in_background :file
end
When creating a new Video object with attachment, the original is saved, but no conversion will be done. Even calling Video.last.file.reprocess! won't to a thing except returning true. (Not sure what "true" means in this case as it didn't work.)
I tried hardcoding the path to ffmpeg in Paperclip::options[:command_path]. I even tried deleting the paperclip-ffmpeg.rb file and replacing it with a blank file. Really thinking I'd get an exception by doing the later, instead, I simply got "true" again.
It feels like the paperclip-ffmpeg.rb is being loaded, because it is required by config/application.rb, but nothing is called in it when trying to generate a thumbnail or convert a video.
Can anyone help me with this? Thanks in advance!
Looks like I solved this problem myself, and it was caused by something I did.
I wrote my own script to import files and the database from an older app to Rails. The files were in place, but someone I updated the database with the wrong file extensions (in this case, ".jpg" instead of ".MOV").
Paperclip will verify first to see if the original file exists before calling any processor, based on the file name stored in the database. As it didn't, Paperclip just didn't do anything. Once I had the data corrected, everything ran as expected. (I had problems with FFMPEG, but that's a different issue.)
My apologies if I wasted anyone's time. Hope this can be helpful for someone.
I use a similar configuration for one of my project (but Rails 3.1.1) and everything works fine. I added paperclip-ffmpeg to my Gemfile not with config/application.rb. Maybe this helps!?