Did Rails Routing change the way it handles the params[:path]? - ruby-on-rails

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')

Related

Rails routing: Wildcard and german umlauts

I'm just developing a WebDAV interface for a Rails App. Therefor I'm routing all webdav.example.com/path/to/folder paths to a webdav controller:
scope controller: 'webdav', constraints: {subdomain: 'webdav'} do
get '*path', action: 'show'
# some more webdav specific routes...
end
Everything works fine, but for a folder called 'Verträge' the native Windows client now requests webdav.example.com/Vertr%E4ge which unfortunately breaks the rails routing process raising an ActionController::BadRequest...
After some research I figured out that i.e. Gems like HighVoltage have the same problem.
Does anybody has an idea to solve this? Regardless of telling Windows to send a real 'ä' or fixing it at rails side...
UPDATE:
%E4 belongs to ISO-8859-1 (ISO Latin 1) Character Encoding, but Rails routing works with UTF-8.
So GET webdav.example.com/Vertr%C3%A4ge works perfectly fine.
How do I get either Windows to UTF8 encode the urls or Rails to recognize and convert the urls properly before dispatching the request?
Currently ended up patching ActionDispatch::Routing::RouteSet::Dispatcher this way: https://gist.github.com/sdhull/9240273
Other solutions / discussions are welcome :)

what changes in routing were made between Rails 3 and Rails 4?

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

Two almost identical Rails projects, missing gem helper file in one but not the other

I have two rails projects under the same parent within my home directory with the same environment. Both use the authorize-net (1.5.2) gem. I'm using ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin11.4.0], Rails 2.3.14, and rvm 1.14.3 on Mac OS X 10.8.1. Both have config.gem 'authorize-net', :lib => 'authorize_net in their config/environment.rb, both have helper :authorize_net at the top of their relevant controllers, both have helper :all at the top of their application_controller.rb. Yet one works fine and the other gets a MissingSourceFile (Missing helper file helpers/authorize_net_helper.rb) error. The helper file is in fact located at ~/.rvm/gems/ruby-1.8.7-p358#global/gems/authorize-net-1.5.2/lib/app/helpers/authorize_net_helper.rb
I cannot for the life of me figure out why one works but not the other. Can anyone point me in the right direction? How can I figure out what path Rails is using to find this helper in each case?
One thing I've learned over the years of using the StackExchange universe is that when I have a weird problem and don't get an answer within a couple of days, it's something stupid I did that no one else did or probably ever will do. I imagine this is one of those things, but I'll never know because the problem has gone away and I don't know why.
Realizing that the working project came from authorize.net's example and the non-working one didn't, I discovered that the authorize-net gem had a generator that I had not used. So I went thru the generator code and realized I was missing an initializer that I was sure I had already created. This initializer just loads some constants (api_login_id and api_transaction_key) from a YML file and has nothing having to do with paths, but I created it anyway before realizing I had in fact created it before but put it in controllers instead of config/initializers. Anyway, when I restarted WEBrick, everything worked, no path issues. Now I have restarted WEBrick MANY times before, including just before posting this question. But this time the problem went away.
I HATE when this happens.

How can I figure out which line of my routes.rb file has Rails 2 grammar?

I've converted my (pretty large) routes.rb file to Rails 3 style, but I'm still getting deprecation warnings. I suspect there is some option or flag in there that I missed, but I don't know where it is.
Is there a trick I can do to figure out where it's coming from? I suppose I could iteratively comment out blocks of it and then run the checker on it… ugh.
Rather than it being your own config/routes.rb file, it could be one provided by a gem such as declarative_authorization or ckeditor. Check the gems you're using on the project if they contain a config/routes.rb file.
If none of them contain one, then please show us your config/routes.rb.
Use the Rails Upgrade plugin to check for outdated syntax

Compiling / building ruby online from a working rails application

I'm totally new to Ruby but not to programming. All I did was going through try ruby and reading differences from other few languages I know better (mostly PHP and some Python). So I have no idea how Rails differ from Ruby and maybe this is an absurd question.
Anyways...
I don't want (or am able) to install Ruby on my machine and I'd still like to build a single working source file. Is it possible to have an online compiler of some sort? If so, how?
If I write a Rails web site (comprised of either one or many files) using any given host (that far I know I can), would I be able to use that same code with very minor modifications and just run as a Ruby app? Again, how?
(new) What about the other way around: a Ruby app turning into a Rails web page? Easy to do?
I really hope for a "yes" on them all, but I doubt on the 1st and not so much on the last. :)
There are online "IDEs" you can use to try out ruby:
http://ideone.com
http://codepad.org
But mind you that Ruby on Rails is a framework written in Ruby and those sites don't have RoR installed. Also note you that a Rails app has many, many files.
If you have the same code and same server configuration (version of ruby, database, plugins, etc.) you should only need minor modifications to the config file.
Ruby on Rails is on Ruby. So whatever works on Ruby should work just fine on RoR with minor modifications. However, you'll probably want to rewrite the app to take advantage of many of the features RoR provides.

Resources