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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rick (Guest)
on 2005-12-29 23: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:

/companies/amsterdam/ruby/

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,

Rick
Rick (Guest)
on 2005-12-30 00:55
Anyone? :-)
Terje Pedersen (Guest)
on 2005-12-30 01:35
(Received via mailing list)
def method_missing(method)
end
Jeremy M. (Guest)
on 2005-12-30 01: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])
  end
end

Hope that is a start.
Rick (Guest)
on 2005-12-30 15:28
Thanks a lot for the feedback, i got it working now!
This topic is locked and can not be replied to.