Johan Mickelin | 19 Jul 23:52

Routes


Hi there,
I'm having an issue with routes I frankly dont get.
I have a controller named map which takes in a hash string and converts
that to an actual url, works great

so localhost:3000/f3gg or whatever works fine

now, I have a controller which I want to use to add some records (needs
to go through AJAX)

I want two strings, from and to but nevermind that for now since I'm too
stupid to even get one string working

my routes.rb look like this

  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'
  map.connect ':map', :controller=>'map', :action=> 'index'
  map.connect ':from', :controller=>'share', :action=> 'index'
  map.connect '', :controller => "map"

the map one in the middle works fine, the controller looks like this:
(cut out all the irrelevant stuff)

class MapController < ApplicationController
  def index
    @map = getmap
  end
  def getmap
(Continue reading)

Phlip | 20 Jul 01:36

Re: Routes


Johan Mickelin wrote:

> I want two strings, from and to but nevermind that for now since I'm too
> stupid to even get one string working

How is assert_routing working out for you?

> my routes.rb look like this
> 
>   map.connect ':controller/:action/:id.:format'
>   map.connect ':controller/:action/:id'
>   map.connect ':map', :controller=>'map', :action=> 'index'
>   map.connect ':from', :controller=>'share', :action=> 'index'
>   map.connect '', :controller => "map"

The router drops thru each connect, in order, looking for an adequate match. 
Because you have a controller called Share, the /share routes matches 
':controller...' prematurely.

Always put the generic routes _below_ the specific routes.

After all this works, name your routes. I don't think Rails has a reason not to 
name all routes:

   map.from_share ':from', :controller=>'share', :action=> 'index'

Now you can use from_share_url in your source, instead of reassembling the url 
with url_for.

(Continue reading)


Gmane