Another adopted rails app issue. I have the following in my routes.rb file. It is currently not working (not sure if it ever was). We have upgraded from 3.1 -> 3.2.13
scope '/arc' do
match '/api/get-images-by-location/:global_id' => 'api#get_images_by_location'
end
and I get the following error:
ActionController::RoutingError (No route matches [GET] "/arc/api/get-images-by-location/168"):
Should this route be working? I think it should but clearly it isn't.
thx for any help
edit 1
Added namespace for arc
Related
After upgrading to Rails 6.1, I'm getting following error:
undefined method `find_script_name' for nil:NilClass
In this case the route is being used is root_path but getting this for many other routes too! routes.rb is as following (tried like this after removing all other route definitions)
Rails.application.routes.draw do
root 'home#index'
end
Only relevant thing I found online is this commit. Anyone has idea what could be wrong?
I'm running on ruby 2.7.2
it looks like a bug in the current release of rails 6.1
https://github.com/rails/rails/issues/42218
the current fix is to prefix all path helper calls inside the views with:
Rails.application.routes.url_helpers.
so session_path becomes Rails.application.routes.url_helpers.session_path
I am creating a simple suggestion box app (to learn Rails) and am getting the following Rails routing error when I go to "/suggestion-boxes" running on my local machine (localhost:3000)
"Routing Error
No route matches [GET] "/suggestion-boxes"
In my routes.rb file I have:
SuggestionBoxApp::Application.routes.draw do
resources :suggestion_boxes
end
This is what I get when I run rake routes:
suggestion-box-app$ rake routes
suggestion_boxes GET /suggestion_boxes(.:format) suggestion_boxes#index
POST /suggestion_boxes(.:format) suggestion_boxes#create
new_suggestion_box GET /suggestion_boxes/new(.:format) suggestion_boxes#new
edit_suggestion_box GET /suggestion_boxes/:id/edit(.:format) suggestion_boxes#edit
suggestion_box GET /suggestion_boxes/:id(.:format) suggestion_boxes#show
PUT /suggestion_boxes/:id(.:format) suggestion_boxes#update
DELETE /suggestion_boxes/:id(.:format) suggestion_boxes#destroy
However, if I modify my routes file to
SuggestionBoxApp::Application.routes.draw do
get "suggestion-boxes" => "suggestion_boxes#index"
end
Then the page "/suggestion-boxes" displays as per the index action in my SuggestionBoxesController.
I tried restarting my server but this had no impact. While I of course can go with using GET, this error makes no sense, and I would like understand what is causing it.
Any insights would be very much appreciated.
The error is that you are not renaming the REST route, instead the controller one.
Try declaring
resources :suggestion_boxes, :as => "suggestion-boxes"
in your config/routes.rb file.
Somewhere in your code you are calling to suggestion-boxes controller which does not exist. Your controller is suggestion_boxes, spelling. So where every you have "suggestion-boxes" you should replace with "suggestion_boxes". The code that you added create an alias that matches 'suggestion-boxes' to the index action of the suggestion_boxes controller so this resolves it if it is your desired affect. But simply fixing your spelling would resolve your problem. I usually use the second approach if I want the change the URL that user see. Have a look at the routing doc for a better understanding
Following the rails guides' tutorial, I ran into an issue where I learnt about plural vs. singular naming and repercussions. Now that I know this going forward, I'm interested in learning if it's possible to work around this -- without having to rename my controller.
I've passed a new :url_path to form_for (account_path) and my 'rake routes' outputs an entry:
account GET /account/:id(.:format) account#show
I still get the following error when trying to access the page with the form:
Routing Error
No route matches {:action=>"show", :controller=>"account"}
My routes.rb has an entry for the plural resources directory (resources :account)... Understanding that the singular version works, but the controller still represents "many".
Any insight for a green RoR dev?
Assuming it's not a typo - you should write resource :account. Hope that helps.
I implemented a simple custom errors solution.
this one: http://ramblinglabs.com/blog/2012/01/rails-3-1-adding-custom-404-and-500-error-pages
everyhing is working fine except the missing routes in the routes.rb file..
in order to get to my error_controller when there is a missing route i did the wildcard solution: match '*not_found', to: 'errors#error_404'
but... now when i try to enter a sub section of my site which seats under:
/admin, i get to the error page. the wilcard gets triggered, even tough the route for admin section is defined in a different route file, under: config/routes/admin.rb
what can I do?
thanks
edit:
using rails 3.0.20 and ruby 1.8.7
If you're using Rails 3.2+, there is a simpler solution for your routes. First in 'config/application.rb' set your app as the error handler
config.exceptions_app = self.routes
Now when there is an your app will look to your routes to handle it. In 'config/routes.rb' you can add a route such as:
match "/404", :to => "errors#not_found"
A more verbose explanation can be found here.
OK so until I will update to Rails 3.2+
I simply put '*not_found', to: 'errors#error_404' into the last route file that is loaded.
that way its truly in the end of the routes and now all my routes work. and the error is still fired when needed.
I just installed Rails, etc. on a Windows 7 machine.
Created my first app, and am trying to go to the first generated and this is what I get:
Routing Error
No route matches "/say/hello"
Where say is the app name, and hello is the name of the first view.
Thoughts?
If you're implementing very simple routes (and since this is your first app, I'm assuming that's what you want!), make sure you've un-commented the last route in routes.rb:
match ':controller(/:action(/:id(.:format)))'
This will send /say/hello to the hello action of the say controller.
Have you added route in config/routes.rb ?
get 'say#hello'