Cannot load 'paperclip/storage/ftp' when using paperclipftp in Rails 3 - ruby

I've just installed paperclip 2.3.3 and paperclipftp 0.1.0.
Paperclip was working fine, the attachments were saving and everything was great.
Enter paperclipftp.
I've included both gems in my Gemfile, installed it with bundle and made sure all dependencies were satisfied. I've also double checked that all my ftp info is correct and the server is working fine.
When I try to attach a file using ftp:
has_attached_file :photo,
:styles => {
:small => "204x159#",
:original => "460X370#"
},
:storage => :ftp,
:path => "/:attachment/:attachment/:id/:style/:filename",
:url => "http://kickassserver.com/_myfolder/:attachment/:attachment/:id/:style/:filename"
I get the following error:
Paperclip::StorageMethodNotFound in SetupsController#create
Cannot load 'paperclip/storage/ftp'
I'm thinking that paperclipftp isn't actually being loaded by my app. Is there a way I can check to see that it's actually being loaded, or has anyone else experienced this?
Thanks,
Matt

I have ruby 1.9.2p180 and the problem is that the timeout class being loaded.
Only add,
require 'timeout'
to the application.rb and this will fix your error.

Related

Enabling SSL for a thin server and sinatra

I'm trying to enable SSL for my thin server web app so that it can work over HTTPS.
I have done the following:-
launching of thin web server
MyApp.run! :host => '127.0.0.1', :port => 9090, :sslenable => true, :sslverifyclient => OpenSSL::SSL::VERIFY_NONE,
:sslcertificate => '.ssl/server_key.pem', :sslprivatekey => '.ssl/key.pem'
I generated a self signed certificate and private key using the openssl module in Ruby, created a directory called .ssl and stored them there as pem files.
The web framework I'm using for my web app is Sinatra. I'm also using the rack-ssl gem in the following way..
myapp.rb
require 'rack/ssl'
class MyApp < Sinatra ::Base
use Rack::SSL
use Rack::Session::Cookie,
:key => '_rack_session',
:path => '/',
:expire_after => 2592000,
:secret => ''
...
end
When I go to http://localhost:9090, I would expect to see my app displayed as normal but with a padlock and a cross through it as any http request is being redirected to https and I see the error "webpage is not available". However when I remove ssl-rack ruby gem and restart my app and go to https://localhost:9090,i get an ssl connection error with the following details:
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error code: ERR_SSL_PROTOCOL_ERROR
Can anyone please advise me on how best to configure a thin server to enable SSL?
I'm running Sinatra and Thin on Heroku with SSL using the Rack::SslEnforcer, doing this:
if production?
require 'rack/ssl-enforcer'
use Rack::SslEnforcer
end
This should be before you enable :sessions in your file. So, Rack::SslEnforcer needs to be placed above the session part when you configure your app.
Somewhat unrelated, but perhaps still relevant, you might consider adding:
require 'encrypted_cookie'
cookie_config = {
:key => 'usr',
:path => "/",
:expire_after => 86400, # one day in seconds
:secret => ENV["COOKIE_KEY"],
:httponly => true
}
cookie_config.merge!( :secure => true ) if production?
use Rack::Session::EncryptedCookie, cookie_config
You also need to set the COOKIE_KEY in your environment to something secret and long-ish.

Rack/Sinatra Method Not Allowed

I am developing a simple web app using Sinatra and using rack as the middleware and hence have a config.ru.
To run the application I use shotgun config.ru.
I have no problem when the application does a GET request. But my app has a couple of POST requests, and when I submit a form via POST method, I get this strange error:
Method Not Allowed
Following is the content of my config.ru:
require "rack"
require 'rack/contrib/try_static'
require File.expand_path("app", File.dirname(__FILE__))
use Rack::TryStatic, :root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination']), :urls => %w[/]
run App
Any idea what could resolve the issue?
Thank You
The following will not respond to posts:
get '/hi' do
"Hello World!"
end
It is quite possible that you will need to do something like this:
post '/hi' do
# do post stuff
end
I solved the issue.
It was a problem with rack.
I replaced
use Rack::TryStatic,
:root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination']),
:urls => %w[/]
with:
use Rack::Static,
:urls => ["/#{App::SETTINGS.site.config['destination']}"],
:root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination'])

Sending mails automatically through action mailer Rails 3.1

I have to send weekly emails to all the user about the latest things happening. I am using ActionMailer to accomplish other mailing task however I have no clue how to automate the weekly emails.
Update
I found whenever gem which could be used to schedule cron jobs. I guess this could be used to send weekly emails which I intend to. Still looking how to make it work with ActionMailer will update once I find the solution
Update 2
This is what I have done so far using whenever gem:-
in schedule.rb
every 1.minute do
runner "User.weekly_update", :environment => 'development'
end
in users_mailer.rb
def weekly_mail(email)
mail(:to => email, :subject => "Weekly email from footyaddicts")
end
in users.rb
def self.weekly_update
#user = User.all
#user.each do |u|
UsersMailer.weekly_mail(u.email).deliver
end
end
If i try to run User.weekly_update from the console I am able to get the mails. I am testing in development mode and using rvm. I checked my crontab file and it has got the right stuff.
However I am not getting any mails automatically from the app. Any clue what might be wrong?
Thanks,
OK so it turns out to be a path issue with whenever gem, and the problem was created when I installed another version of ruby.
In my machine the new ruby version is installed in /usr/local/bin/ruby. In my rails app I had to go to the file script/rails and replace #!/usr/bin/env ruby with #!/usr/local/bin/ruby.
I found this out by visiting cron.log file which showed this error message :- /usr/bin/env: ruby: No such file or directory
I made a cron.log file to log the cron error this is what I did in my schedule.rb code written in the question :-
every 2.minutes do
runner "User.weekly_update", :environment => 'development', :output => 'log/cron.log'
end
I am getting periodic mails now.
It seems like you haven't configured ActionMailer settings.
First check out the logs from console, whether the mailing process is working(paste your logs).
If yes then do following steps.
add this in your gemfile.
gem 'tlsmail'
run
bundle install
write these configuration setting in your config/environments/development.rb file
require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:enable_starttls_auto => true,
:authentication => :login,
:user_name => "<address>#gmail.com",
:password => "<password>"
}
config.action_mailer.raise_delivery_errors = true
add your working password/email against user_name and password.
Don't forget to restart server.

reload rails.root/app/resources/* per request

I have a rails app with a folder rails.root/app/resources where I keep some library code.
This library code is used in a rack app that I mount in routes.rb in my Rails application
# rails.root/app/resources/file_resource.rb
# routes.rb
mount DAV4Rack::Handler.new(
:root => Rails.root.to_s,
:resource_class => FileResource
), :at => '/', :constraints => {:subdomain => "w"}
How can I make the FileResource reload on each request in development?
I tried autoload_paths, reload_plugin, none seem to work.
I think it has something to do with the code in routes.rb.
If I make a file rails.root/app/resources/my_helper.rb and use MyHelper.test() inside FileResource, the MyHelper gets reloaded.
No, I don't want to move this in 'lib' folder.
I am currently using the following hack, if anyone has a better solution please do share!
# config/environments/development.rb
root = config.root
config.to_prepare do
load "#{root}/app/resources/file_resource.rb"
end

ies4linux with selenium and rspec

I use selenium, usually with firefox, to test my rails apps and it's all fine. I want to run my tests in IE6 as well. I'm in ubuntu, using the ruby selenium-client gem. For IE6 i use ies4linux, this is an executable which is at /home/max/.ies4linux/bin/ie6
I'm editing my selenium conf to try to get it to use the above, but can't get it working. Here's what i have at the moment:
SELENIUM_CONF = {
:client_options => {
:url => "http://awebsite.com",
:host => "localhost",
:port => 4444,
:browser => "*iexplore /home/max/.ies4linux/bin/ie6",
:javascript_framework => :jquery
}
}
Then when i make a browser in my scripts i call
Selenium::Client::Driver.new(SELENIUM_CONF[:client_options])
It's not happy with what i have in the :browser field at the moment - i get this error:
"Failed to start new browser session: Error while launching browser"
I also tried
:browser => "/home/max/.ies4linux/bin/ie6",
But got a "Browser not supported" error as it expects one from list, *iexplore in this case.
Can anyone tell me how i can get this working?
thanks, max
I don't think there's a way to do that. Selenium uses iehta, and some not-so-used parts of ie that could not be bundled in ie4linux, and even if there were, I wouldn't trust on a test that runs IE under linux.
Why not creating a VM using VirtualBox and pointing your tests to an RC server inside the VM?

Resources