Assets not being served by assets pipeline in Rails 3 - ruby-on-rails-3

I am migrating a big application from Rails 2 to Rails 3.
I added some images to app/assets/images. i.e. app/assets/images/key.png
If I go to http://localhost:3000/assets/key.png I dont see the image. In the server log I see that it was not found and one of the controller started to process the request.
Started GET "/assets/key.png" for 127.0.0.1 at 2013-03-19 17:44:31 -0300
Served asset /key.png - 404 Not Found (49ms)
Processing by DfcController#index as PNG
Parameters: {"path"=>"assets/key"}
In development.rb I have the lines:
config.assets.debug = true
config.serve_static_assets = false
And in application.rb I have the lines:
config.assets.enabled = true
config.assets.version = '1.0'
Any help?

You should change
config.serve_static_assets = true
in your development.rb. Because during development, your rails application server acts as your web server too and should serve the static assets.

Related

Rails - Method not allowed when executing POST methods (error 405)

I come from this post:
Rails using puma, change localhost:3000 to localhost:3000/example
I have fixed this issue, but now I receive "Method not allowed" when I do a post request. I have been reading and tried this solution:
Post returns 405 method not allowed
I know where is the problem: If I put in application.rb lines 1- and 2-, all assets are shown correctly and post methods aren't doing it. If I comment these lines, methods works but assets don't.
Application.rb:
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
config.action_dispatch.rescue_responses["BadTaste"] = :bad_request
1- config.action_controller.asset_host = "https://www.sevilla.org"
2- config.assets.prefix = '/autorizaciones-movilidad'
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
Routes:
Rails.application.routes.draw do
#resources :assets, path: '/autorizaciones-movilidad'
scope "/autorizaciones-movilidad" do
get 'vehicles/new'
get 'vehicles/create'
...
get 'vehicles/update'
end
end
Controller structure:
Don't know how to solve it.
It is deployed with a proxy server (in localhost it was working ok)

Where to specify build-specific runtime settings?

I'm starting to write a ST 2.4 app using Sencha Cmd 5. Where do I specify build-specific runtime settings, such as server hostname to use in app for ajax calls?
Example for server host:
production: www.example.com
development: local.example.com
testing: test.example.com
Obviously, my app is responsible for taking the hostname and using for the ajax call url. But can I specify my app settings such as server hostname in app.json, such that it will be an available Javascript object when the app launches?
Sorry for bad english.!!
set url path as a window variable, so that it becomes global variable, you access in your ajax call
Eg:
window.WebUrl = "192.168.1.12/AppName";
in your case
production:
window.WebUrl = "www.example.com";
development:
window.WebUrl = "local.example.com";
testing:
window.WebUrl = "test.example.com";
put window.WebUrl in your Index.html,
Include all three, comment whichever url you don't want to enable.
for development:
//window.WebUrl = "www.example.com";
window.WebUrl = "local.example.com";
//window.WebUrl = "test.example.com";

Rails App in Wordpress Subdirectory With NGINX

Still fairly new to NGINX.
I have a wordpress site which will be the root site, and a rails app which should be in a subdirectory (site.com/portal). I previously had this working with Passenger, but wanted to check out Puma (looking for zero downtime deploy).
I have another rails app working fine on Puma, and my wordpress site is working too. But I can't seem to get my portal app to show up underneath my wordpress app. Before, with passenger, I symlinked the portal app inside the wordpress site and added some passenger directives to Nginx.
# Use rails app inside wordpress
location /portal {
rails_env development;
passenger_min_instances 2;
passenger_enabled on;
passenger_base_uri /portal;
}
I tried changing this to use root:
# With symlinked /var/www/portal/public -> /var/www/website/public/portal
location /portal {
root /var/www/portal/public;
}
But no matter what I do I either get forbidden or not found errors.
Everything I've found is for passenger, or a wordpress site inside the rails app. How can I use Puma, and put my rails app inside a wordpress site?
Here are my complete nginx configs for the two sites:
nginx/conf/sites-enabled/local.website.conf
nginx/conf/sites-enabled/ssl.local.portal.conf

Moving Rails app to production with nginx

I'm on a VPS. I created a new rails app with rails new rails_app -d mysql.
I'm running nginx with passenger. I'm running Rails 3.2.12 and Ruby 1.9.3. In my nginx.conf file I added the following to the server directive:
listen 80;
server_name www.mydomain.com;
passenger_enabled on;
root /home/mike/www/rails_app/public;
rails_env production;
When I point to www.mydomain.com I see Welcome aboard You’re riding Ruby on Rails!. When I click on About your application’s environment I get this error:
The page you were looking for doesn't exist.
When I check my production.log I see this error and don't know what to do with it:
ActionController::RoutingError (No route matches [GET] "/rails/info/properties")
I've been up all night and have read all SO issues similar to this but still I cannot resolve my issue. If I run this in development everything works fine.
EDIT
I found this explanation for a Rails 2.3.4 problem: The link fires off an AJAX request to rails/info/properties. The properties action is defined in the Rails::InfoController which lives in /rails/railties/builtin/rails_info/rails/info_controller.rb.
The route doesn't need to be explicitly defined because it conforms to the Rails default route of :controller/:action/:id (although there is no ID in this case and the controller lives within a Rails namespace.)
But I don't see info_controller.rb anywhere.
Ok I found this: config.consider_all_requests_local is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the Rails::Info controller will show the application runtime context in /rails/info/properties. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement local_request? in controllers to specify which requests should provide debugging information on errors.
but setting this to false does nothing.
EDIT 2
Ok, I'm an idiot. Found this somewhere: You're clicking the "About your application’s environment" link on the Rails default index.html page. This link only works in development environment, not in production.
And this entire night I thought my Rails app wasn't working. So I guess I'll give up and go to sleep.
You forgot to add passenger_base_uri:
server {
listen 80;
server_name domain.com;
charset utf-8;
root /www/domain.com/public_html;
passenger_enabled on;
passenger_base_uri /blog;
rails_spawn_method smart;
rails_env production;
}
Also check that passenger and rails work in the same environment (production or development).
For those who might encounter this problem in the future, first check your production logs in your server.
ssh into your server, ssh username#serverIP
Check the last 20 or so error messages tail -20 /home/username/appname/current/log/production.log
If it's a bug in your code (mine was returning an empty array due to an empty db), then fix that bug and run cap production deploy once again.
Repeat to check for more errors.
Same problem is also faced by me, but I found later wards due to permission, our application is not able to access the specific folder.
Try this command :
chmod -R 777 {name of your project folder}/

"config.force_ssl = true" not forcing HTTPS

I am running Rails 3.1 and have tried putting the above line in development.rb and application .rb (not both at the same time) but it doesn't seem to do anything. My request are still working on HTTP. Isn't this meant to force all requests to use HTTPS? I'm sure I've missed something very obvious here but can't for the life of me think of what - being a newbie doesn't help either.
Any help would be greatly appreciated.
Cheers,
Dany.
It wont work locally, have you deployed it?
It will work provided that your local server (webrick?) is configured to use SSL, below is one way to do that via script/rails:
#!/usr/bin/env ruby.exe
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
# require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3000,
:SSLEnable => false, # set to true to automatically generate SSL cert
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
#:SSLCertificate => OpenSSL::X509::Certificate.new(File.open("ssl.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'