I am new to rails and have been working thru a number of tutorials. I have a controller with the following actions: Contact and Home. The routes.rb has the following:
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
# The priority is based upon order of creation:
# first created -> highest priority.
Everything else in the standard routes is commented
When I try to reach the page http://localhost:3000/pages/home
I get
Routing Error
No route matches "/pages/home"
on the web page.
I restarted the rails server and checked routes with rake routes - results below
pages_home GET /pages/home(.:format) {:controller=>"pages", :action=>"home"}
pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"}
I tried other tutorials that were based on 2.3 version of rails and had lots of routing issues but was running 3.0 instead so went to 3.0 tutorial. Same routing issues. I even have the same problem when I put a static page "hello world" in the public folder. According to tutorial, that should just come up but I get same routing error message.
Any suggestions would be most appreciated.
I solved my problem. A real noob mistake. Running rails, it is important to be in the right directory. I was in a previous example directory so the routes I needed were not there.
Related
I have a following definition in my routes.rb
match "/block/:name/:action" => proc { |env|
#heavy magic happens here
}
I use it for handling rendering of cells. My problem is that the following link:
/block/reporting%2Fother%2Fexample/new?exampleable_id=23736&exampleable_type=Abc%3A%3ASomeType
works perfectly fine in development mode, but in production I get "404 Not Found". The only difference between production and development urls is that the one in development uses http and the one in production uses https. I would understand if I wrote a faulty code my proc block, but for the love of god I can't understand why it is not matched in production environment, when it works perfectly fine in development.
Any hint on how to debug this is highly appreciated. There is not so much hair left on my head.
I got this error even when if I finally launched the project in production environment on my local machine. The thing is we do not use Thin in production. We use passenger. After I finally got passenger working locally, I managed to recreate the error.
It turned out that with passenger, the :name in aforementioned route wasn't interpreted as "reporting%2Fother%2Fexample", but possibly as /block/reporting/other/example/new" with the rest not matched, of course.
I fixed the error by replacing
match "/block/:name/:action"
to
match "/block/*name/:action"
I hope this answer to my own question helps someone in the future.
wow. going super nuts here trying to deploy to staging on heroku cedar from Rails 3.2.2. I've gotten everything to work, but I wanted to run these issues up the flagpole to see if there's something wrong with... me. eheh
Both of these issues give me the not-helpful "We're sorry, but something went wrong." error page. So it was frustrating when I had 2 different issues (that acted like 3) in one deploy (that worked fine on my local).
Heroku won't give me my logs.
when I run
heroku logs
I get a long error message that starts with,
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Permission denied - connect(2) (Errno::EACCES)
so i've been doing all this troubleshooting via small slices of commits. maddening.
Heroku chokes when it can't find an image with image_tag
this works on heroku:
= image_tag("content/portfolio/maskphoto_rubble_rebel_blur.jpg", :alt => params[:photo], :width => "100%")
This doesn't (only difference is an extra letter in the file name, though it works on my local):
= image_tag("content/portfolio/maskphoto_rubble_rebell_blur.jpg", :alt => params[:photo], :width => "100%")
Am i nuts in thinking that heroku should just serve up the image tag as-is and let it just not display, rather than crashing the entire page? I'm running compass; not sure if that has anything to do with anything.
Heroku hates nested expressions in an array ref
this works:
n = f.index(params[:photo]) +1
#nextphoto = f[ n ]
this doesn't (but does on my local):
#nextphoto = f[ f.index(params[:photo]) +1 ]
i guess it's better form to separate expressions, but still. why would it work on my local and not on deploy?
I can't directly answer all of your questions, but here are a few things to look at:
Heroku won't give me my logs.
The error you are getting indicates Permission denied ... Perhaps your account credentials are not setup properly? I see you are on a windows box ... on a unix machine, the heroku client writes a file at ~/.heroku/credentials with the username and what appears to be an API token. Check to see if you have a similar file. You can also check https://toolbelt.herokuapp.com/windows and make sure you have successfully performed the heroku login command.
Heroku chokes when it can't find an image with image_tag
I don't have many ideas here. Perhaps it is related to the asset-pipeline?
Heroku hates nested expressions in an array ref
This one doesn't make a whole lot of sense either. Perhaps the logs can shed some light here. I did notice that you appear to be running Ruby 1.9.3 on your system, and I don't believe heroku supports 1.9.3 yet. Maybe you have hit a version-specific bug.
I hope that helps. Good luck.
I'm trying to deploy my rails 3.1.3 app in a subdirectory on the server:
Apache (reverse proxy) => unicorn (listening on localhost:5000)
The problem is with url_helper.
via the --path switch in unicorn I'm setting my /subdir
It gets picked up by rails; DashboardController.config.relative_url_root gives me that subdir.
But when I use something like 'members_path' in my view it gives me '/members' and not '/subdir/members'
what am I missing?
I had exactly the same problem. Two things were missing/faulty in my setup.
My web-server had an superflous, faiulty rewrite-rule, rewriting /prefix/<controller> to just /controller.
It seems Rails3 routing are by default ignoring relative_url_root. (Stupid IMHO) There's a good tip in https://stackoverflow.com/a/5457484/103192 that shows a trick to make it work again.
Otherwise, you can wrap the run statement in your config.ru with the
following block:
map ActionController::Base.config.relative_url_root || "/" do
run FooApp::Application
end
I now have it working much like one would want it to work.
I'm new to rails and very new to Heroku, but I've recently hosted my app up on Heroku and am getting the following error in my log:
Started GET "/stylesheets/all.css" for ...
ActionController::RoutingError (No route matches "/stylesheets/all.css"):
I stumbled across this forum (http://railsforum.com/viewtopic.php?id=38540) where someone was able to fix a similar problem by setting config.serve_static_assets = true in their config/environments/prodcution.rb, but this did not work for me. Does anyone have any thoughts on this? To clarify, I only get this error in production, not in dev. Thanks.
Also, rather interesting is that I am actually able to access /stylesheets/styles.css with no problem...
Why not just add a blank all.css file?
When I run rails s it loads up and everything works. When I browse to a page several lines of information are printed. Mostly this is the webpage getting the assets for the page. I really don't need to see this and have it clutter my screen. Is there a way to customize what gets printed in console?
Thanks
For assets pipeline messages it seems that you can't (yet). See How to disable logging of asset pipeline (sprockets) messages in Rails 3.1? and the rails issue on Github
You can do it in part by using these lines (credits) in your development.rb file
config.after_initialize do |app|
app.assets.logger = Logger.new('/dev/null')
end
For Rails 3.1, inside config/environments/development.rb, set the following to false:
config.assets.debug = false
Your logs will show you everything you want to see minus the assets.
You can configure the logging detail of the rails dev server by setting config.log_level in environments/development.rb. Setting it to :warn will get rid of most of the logging (you can always send your own messages with whatever log level you want so they still get printed).
http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels