Forum: Ruby on Rails How to handle a non existing action in a controller?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8de41586b63465e0fc0005e8312d7ae1?d=identicon&s=25 Rick (Guest)
on 2005-12-29 22:53
Hello, i'm currently building a website in which i have to customise the
url to the data.

An example:
i have a company which is situated in Amsterdam and it's name is Ruby,
then i would like to have the following URL:


But since there are a lot of cities that have companies i can't make a
define for all of these.

How to fix?

Thanks in advance,

8de41586b63465e0fc0005e8312d7ae1?d=identicon&s=25 Rick (Guest)
on 2005-12-29 23:55
Anyone? :-)
977b5b70acd889eaa1244aa55158f3d3?d=identicon&s=25 Terje Pedersen (Guest)
on 2005-12-30 00:35
(Received via mailing list)
def method_missing(method)
E5addfb886fa24edf1fcf9473a9b5a34?d=identicon&s=25 Jeremy Maziarz (jmaziarz)
on 2005-12-30 00:36
You could set up a route in config/routes.rb something like:

  map.connect '/companies/:city/:company_name',
              :controller => 'companies',
              :action => 'show'

That would give you params[:city] and params[:company_name] to work
with. So in your controller you could do something like:

class CompaniesController < ApplicationController
  def show
    @company = Company.find_by_name(params[:company_name])
    @city = City.find_by_name(params[:city])

Hope that is a start.
8de41586b63465e0fc0005e8312d7ae1?d=identicon&s=25 Rick (Guest)
on 2005-12-30 14:28
Thanks a lot for the feedback, i got it working now!
This topic is locked and can not be replied to.