Rails App doesn't work on production enviroment - ruby-on-rails-3

I have a rails app set up with Nginx + Passenger. When i have rails_env development; on my nginx.conf everything works fine, but when I remove it so the app get server on production env it just doesnt work, seems like its not loading gems or something. Feel free to take a look at the errors here www.luisurraca.co.cc
error message:
undefined method `has_attached_file' for #<Class:0x00000003b0be10>
Exception class:
NoMethodError
Right now its referring to the paperclip gem, but if i start removing gems from the gemfile it will display error from some other gem and so on.
Any ideas what the issue might be?

You probably defined paperclip/whatever in development group and it is not installed with bundle install --deployment. To see installed gems do bundle show not gem list.
did you specify ruby path for nginx? it should look like this:
http {
passenger_root /home/rlisowski/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.13;
passenger_ruby /home/rlisowski/.rvm/wrappers/ruby-1.9.3-p194/ruby;
# ....

Related

How to set sinatra-authentication to use erb instead of haml?

I'm trying to set up the sinatra-authentication gem in a simple sinatra app, and running into an issue where sinatra can't find the correct views. I understand that sinatra-authentication uses haml by default, but I'm using erb in this app.
This in mind, I found in the sinatra-authenticaiton docs that there is a setting which allows you to change the template engine, by adding the following to your app file:
configure do
set :template_engine, :erb # for example
end
I've added this to my app.rb file, and sinatra is still looking for the signup.haml when I try to hit the /signup route in my app.
A couple of notes:
I've included the gem in my Gemfile, and successfuly run a bundle install on my app.
source 'https://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'pg'
gem 'dm-postgres-adapter'
gem 'sinatra-authentication'
I saw something in the documentation that suggested that I may need to specify the location of my view files, so I added the following to my configuration block.
set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "views/"
**I think I've required the gem accurately in my app file by adding
require "sinatra-authentication"
use Rack::Session::Cookie, :secret => 'mys3cr3tk3y'
This gist is a current representation of my app.rb file in the root of my sinatra app. https://gist.github.com/rriggin/5378641#file-gistfile1-txt
Here is a screenshot of the error sinatra throws: http://cl.ly/image/0y041t0K3u3O
When I run the app locally, a 'dm-users' table is created in my local db as expected.
Is there another configuration setting that I'm missing in order to get sinatra-authentication to properly look for the erb templates rather than haml files. Any help would be greatly appreciated.
Thanks
The specs don't test that the template_engine setting works, and looking at the way the setting is called, I believe it's not correct, i.e.
send settings.template_engine, get_view_as_string("index.#{settings.template_engine}"), :layout => use_layout?
might better work as:
send app.settings.template_engine, get_view_as_string("index.#{app.settings.template_engine}"), :layout => use_layout?
that's what I reckon. If you fork the project, change the line and add it to your Gemfile and it works then consider writing a quick spec for it and you'll have improved the mainline of that project as well as fixed your problem.

Rails 3 - Error after deploying to Heroku

I have an application working in localhost and also heroku. The last time that I pushed the new version to heroku I got an error during heroku db:migrate and did heroku db:push and everything was ok.
I get the following error when executing the App.
/app/.bundle/gems/ruby/1.9.1/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant AnswersController::Authentication (NameError)
Here is the relevant code
class AnswersController < ApplicationController
include Authentication
...
Authentication is a module defined in lib:
# encoding: utf-8
require 'base64'
require 'openssl'
module Authentication
...
It is working in localhost but not in heroku.
Any help??
Thanks
Try adding the lib folder to your the config.auto_load path in application.rb
config.autoload_paths += %W(#{config.root}/lib)
Also, take a look at this link.

Routing error while searching for javascript

My app worked a few days ago.
I have switched to 'thin' from webrick
now I get
2011-12-28T07:08:53+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/jquery.livequery-6725741b06c676d9173d5056b277caeb.js"):
I saw on other question that they were told to set this to true
config.serve_static_assets = false
but heroku recommends against that.
I have tried both using rake assets:precompile locally and then pushing and also without it and let heroku precompile.
Both give same error
How do I make sure the javascripts are served, compiled and available?
Why is the error occuring?
I'm using rails 3.1.3 on cedar, Latest Thin.
I was able to solve this using the question Rails 3.1 asset precompilation - include all javascript files
so.. problem solved

Delayed_job(2.1.4) + Rails(3.0.10) undefined method `delay'

I upgrading a rails application to rails(3.0.10) and update the gem delayed_job. I updated my migration for the table delayed_job but unfortunatly the method ".delay" doesn't work.
NoMethodError: undefined method `delay' for #<User:0x10394d140>
I didn't find a solution for that. I did : "bundle install", I restarted the server, tried to instal as plugin...
Do you have any ideas?
Thanks.
UPDATE :
I fixed the problem but created a file config/initializer/delayed_job.rb with
require 'delayed_job'
Delayed::Worker.backend = :active_record
Sometimes gems just refuse to install properly. I think what you should do is (assuming you have git installed, otherwise go here https://github.com/tobi/delayed_job and download delayed_job as a zip file)
git clone https://github.com/tobi/delayed_job.git
take what he has in his lib folder and put it in yours. wherever you need to use his methods then do
require 'delayed_job'
in the top of those files
I checked this tutorial, it shows a way to setup in rails 3
http://www.dixis.com/?p=335
it suggests using this in your gemfile
gem "delayed_job", :git => 'git://github.com/collectiveidea/delayed_job.git'
(if it doesn't work with this either, then try the same thing that i did, but replace
git clone https://github.com/tobi/delayed_job.git
with
git clone https://github.com/collectiveidea/delayed_job.git
tell me if anything works

Heroku app crashes, logs say "No such file to load -- nokogiri (LoadError)"

I had a working app, added Nokogiri, to parse some xml, runs fine locally.
My Gemfile includes: gem 'nokogiri'
I ran bundle install and verified my Gemfile.lock includes DEPENDENCIES ... nokogiri
In my controller class I added (didnt thinkI had to but got an error locally if I didnt):
class MydealController < ApplicationController
require 'rubygems'
require 'open-uri'
require 'nokogiri'
when I use my browser to get the url in MydealController that uses nokogiri doc = Nokogiri::XML(getresult) Heroku crashes.
heroku logs shows this error No such file to load -- nokogiri (LoadError)
Looking at what happens when I git push heroku I do not see nokogiri on the list of many many gems that get installed. Heroku says the push was fine, but nokogiri is not listed and I get the aforementioned error...
It seems that when using Windows Gemfile.lock will contain version of nokogiri gem specific for windows, solution is to remove Gemfile.lock and push to heroku.
More info on this subject here
Your mission should you choose to accept it.
Ensure:
nokogiri is in Gemfile.lock
Gemfile.lock is committed to git
you push the commit that has nokogiri in Gemfile.lock to Heroku
Good luck! This message will self destruct in 10 seconds...
Just had the same problem -- you have to run bundle install to get it added to the Gemfile.lock which heroku looks at to find uninstalled dependencies.
This might help to understand the reason:
http://devcenter.heroku.com/articles/ps
Indeed removing Gemfile.lock might help. All other compiled gem will cause isseu. Best way is to ask Heroku's support.
Only found this article:
http://ganeshprasadsr.blogspot.com/2010/10/installing-nokogiri-for-rails-3-app-on.html
Try to remove require 'nokogiri' from controller.
It works for me.