what changes in routing were made between Rails 3 and Rails 4? - ruby-on-rails

Are those changes major or minor? I'm concerned mostyl because gems for translating routing stopped working (rails-translate-routes - problem with helpers generating paths) and i'm looking for some way to repair it

There are some details about routing changes here Looks like the main changes are the move to the PATCH verb, raising on conflicting named routes, and direct drawing of unicode routes. The first could be significant if you're specifying the PUT verb in your routes or in custom forms in your code. The others are fairly minor for most applications I would guess.

I used this gem and it's doing fine

Related

Automated way to find out unused controllers and methods in Rails

I'm cleaning up an old Rails application, and I managed to do quite a cleanup on the routes files.
I'm trying to figure out a way if it is possible to map the routes file with non-existent controllers and methods so I can further clean up the code.
Is this even possible?
For my specific problem this is a Rails 3 site, but the question I guess applies to all versions of Rails.

How do I get the route for a path, in a rails application?

Given a method and path, I want to ask Rails how that request would be routed, and i want to be able to do this from console, and/or from a rake task. I figure this should be straightforward - ActionDispatch does this for every request, and the route testing methods obviously also do it.
(Currently: Rails 3.0.x, but for the gem I'm writing I will need to be able to do this in Rails 3.0 through 4.1, at minimum, and possibly in older versions as well.)
I've been trying a few things like this:
routes = ActionDispatch::Routing::RouteSet.new
routes.recognize_path('/my/path/23/edit')
or
Rails.application.routes.recognize_path('/my/path/23/edit')
In both cases, I get back "RuntimeError: route set not finalized".
I'm diving through the ActionDispatch code working it out slowly, but if anyone knows the answer off the top of their head it would save me considerable time. So, thank you!
The canonical answer is actually as given in my question:
# GET request
Rails.application.routes.recognize_path('/some/path/63')
# POST request
Rails.application.routes.recognize_path('/some/path', {:method => :post })
It looks like that wasn't working because I'd previously tried initializing RouteSet manually, which had interfered with the environment's ability to properly load the routes. When I restarted the console session, the above commands worked fine.

where are the auto generated routes in rails scaffolding?

Alright, I'm starting to learn rails and so far im really turned off by how much is auto generated and happening behind the scenes without me knowing. I generated scaffolding for posts. and it auto created routes allowing me to edit and see posts (/posts, /posts/:id/edit, /posts/:id/show....etc) When I go into config/routes.rb I see absolutely no mention of these routes. even though they work. Where are these routes? and where can I add custom routes if the ones for the controller are not in routes.rb?
When you run rails generate scaffold post, rails will generate models, controllers, tests, routes, stylesheets etc.
Rails tells you what files it just generated, you can see it in terminal.
In routes.rb there will be a line
resources :post, this is a shorthand for all RESTful actions that were generated in the controller.
You can declare custom routes in the routes.rb file. I.e.:
get 'my_path'=> 'my_controller#my_action'
In General, Rails can do a lot of stuff for you, and you can avoid repeating default behaviour over and over again. But you can also do most stuff yourself, without Rails magic.
Instead of using scaffolds, just run rails generate controller controller_name action1 action2 (..). You'll end up with just a controller, no automatic views, no automatic model etc.
Or you can just create all files and register your components yourself.
The Rails Guides are a good starting point for understanding the magic.

Did Rails Routing change the way it handles the params[:path]?

I recently upgraded a site from Ruby 1.8.7 to Ruby 1.9.2, and from Rails 3.0.x to 3.2.x. I noticed that some of my legacy urls weren't being handled correctly anymore, and wanted to diagnose the issue.
Here's what I noticed.
http://myapp.com/links/oldlink.html had, in my old app, provided a params[:path] of /links/oldlink.html, but now is providing links/oldlink. So it's dropping the leading forwardslash as well as the file extension.
Can anyone help me figure out what's going on here? Of course I can manually change the legacy strings in my database to also drop their forward slashes and file extensions, but that seems like a hacky solution, and I want to make sure I understand the underlying principles that account for this change in the Rails routing behavior.
Thanks!
You should try this in your routes.rb
match '/foo', :to => redirect('/foo.html')

Rails Routes Question

Did the rules for Rails Routes changes from Rails 1.2.3 to Rails 2.2.3? I recently upgraded an application and instead of redirecting to the correct page, it now redirects to the main page (or Route page) for that matter.
The only thing that I can think of is that the routing rules changed in Rails 2.2.3.
Thanks
Yep there were a lot of changes as you can see here (look at the Action Pack Resources section) "This is where the bulk of the action for 2.0 has gone". If you're using the old semi-colon syntax then that could well be the problem. Do you want to post your route config and a quick description of what is not working?
Also, to diagnose routing problems I find running "rake routes" very useful (though set your terminal window to wide).
Chris

Resources