No routes found - ruby-on-rails-3

I recently upgrade to Rails 3, and after fixing most of the issues I have my server running. However, I amgetting a rather usual error:
Started GET "/" for 10.0.0.1 at Sat May 14 00:37:26 +0000 2011
ActionController::RoutingError (No route matches "/"):
when I try to visit http://localhost:9292/
for reference I'm running my server via rackup.
If I look in my routes.rb file, I see:
RailsRoot::Application.routes do
# ...
match '/', :to => "application#show"
root :to => 'application#show'
# ...
end
For reference application is a controller and it does have an action show, and my application is named RailsRoot.
Given that I believe I've constructed my routes correctly it seems likely that I've installed something wrong or something went wrong in the upgrade, but I'm not sure where seeing as almost everything else is working.
Does anyone know why this might be?

In your routes.rb, change this line
RailsRoot::Application.routes do
to this
RailsRoot::Application.routes.draw do

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)

Select SSL Routes serving up rails 4 static pages via highvoltage gem

I have several static erb pages being served up in a ruby rails 4 site via the high voltage gem:
get '/about' => 'high_voltage/pages#show', id: 'about'
get '/contact' => 'high_voltage/pages#show', id: 'contact', :protocol => "https"
get '/privacy' => 'high_voltage/pages#show', id: 'privacy'
This all works well and good, except that the /contact route doesn't redirect or force SSL on, it is happy with whatever protocol is used.
I host the site on engine yard, attempting to put :force_ssl only or variants in the route line resulted in failed deployments - high voltage uses a slightly different set of arguments than normal routes so I suspect there is a conflict somewhere.
Anyone use highvoltage and SSL with rails 4 for select static pages (not the whole site)? Example routes line please.
You can achieve this by overriding the HighVoltage#PagesController see the override section of the documentation.
It might look something like this:
class PagesController < ApplicationController
include HighVoltage::StaticPage
before_filter :ensure_secure_page
private
def ensure_secure_page
if params[:id] == 'contact'
# check to make sure SSL is being use. Redirect to secure page if not.
end
end
end
Next disable the routes that HighVoltage provides:
# config/initializers/high_voltage.rb
HighVoltage.routes = false
Then in your application's routes file you'll need to set up a new route:
# config/routes.rb
get "/pages/*id" => 'pages#show', as: :page, format: false

Routing specs and subdomain constraint

I have a route which is constrained to only run when a subdomain is present, which looks something like this:
# Set the default root for when a subdomain is used.
match '', to: 'public::pages#show', constraints: lambda { |r| r.subdomain.present? && r.subdomain != 'app' }
# Set the default application route.
root :to => "pages#index"
I'm looking to put together some routing specs to test that this routes properly (testing the app manually shows that the route does in fact work just fine) however I'm coming up against a few issues.
My current shot at a routing test for this is simply to supply the entire domain, with subdomain as part of the get() call:
it "routes to public page on subdomain" do
get('http://somesubdomain.example.com/').should route_to("public::pages#show")
end
However this spec fails, where the router has directed to the root event, rather than the intended one.
<{"controller"=>"public::pages", "action"=>"show"}> expected but was
<{"controller"=>"pages", "action"=>"index"}>.
Can anyone suggest why this might not be working?
Sounds like your root :to => "pages#index" route is taking precedence, and the match ''... route is getting ignored. I would try two root routes and set your :constraint lambda on the first one:
# Set the default root for when a subdomain is used.
root to: 'public::pages#show',
constraints: lambda { |r| r.subdomain.present? && r.subdomain != 'app' }
# Set the default application route.
root :to => "pages#index"
See this blog post for more details about using constraints on your root route.

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}/

Subdomain constraint (Rails 3) makes local server (thin) SO SLOW

I recently added a subdomain constraint to my Rails routes file
constraints(:subdomain => 'new') do
devise_for :customers do
get "/customers/sign_up" => "registrations#new"
post "/customers" => "registrations#create"
put "/customers/:id" => "registrations#update"
end
match '/' => 'roxy#index'
namespace :roxy, :path => '/' do
resources :customers
resources :surveys
end
end
In order to test the subdomain routing constraint locally, I added this line to my hosts file.
127.0.0.1 new.localhost.local
Now, I test my app in my browser at the URL new.localhost.local:3000. It takes about 10 - 15 seconds to load every page, which is unreasonably slow. If I remove the subdomain constraint and just go to 127.0.0.1:3000, everything is zippy and fast again.
What am I doing wrong? I'm new to Rails, so please tell me if there is a better way to do subdomain routing in rails, or if there is a setting I need to configure.
Figured it out. It's nothing to do with Rails or subdomains or thin. Turns out, unlike other unixy-things, OS X reserves the .local TLD for mDNS functionality. For every page, the DNS resolution was timing out before loading my app. So I just changed my /etc/hosts file to
127.0.0.1 new.localhost.dev
and everything's working great now.
Read more: http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/