0
votes

I am using friendly url.

I am using that problem when I visit http://localhost:3000/9 it shows the same page as http://localhost:3000/vind-rejse

My Category vind-rejse have the ID of 9

How do I get rails only to respond on http://localhost:3000/vind-rejse?

And how do I link to konkurrancers show action?

My Kategoris controller:

 def show
    @kategori = Kategori.find(params[:id])
    @konkurrancer = @kategori.konkurrancers.find(:all)

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @kategori }
    end
  end

My Konkurrancers controller:

  def show
    @konkurrancer = Konkurrancer.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @konkurrancer }
    end
  end

My routes:

match ':kategoris/:id' => 'konkurrancers#show'
match '/:id' => 'kategoris#show'
1
are you using def to_param #... end?errorhandler
Yes protected def assign_cached_slug self.cached_slug = self.name.gsub(/\s+/, '_').gsub(/[^\w\-]/, '') end def to_param self.name endRails beginner
could you post your controller code (the show action)?errorhandler
I have now posted the two controllers show actionRails beginner

1 Answers

1
votes

Something like this will work:

@kategori = Kategori.find_by_name!(params[:id])

and for your routes

match ':kategoris/:id' => 'konkurrancers#show', :as => 'whatever'

and in your views

<%= link_to "Whatever", whatever_path(9) %>