0

In my view I specify a named route like this:

show.html.erb ->

seo_path(:id => "45")

Now in my routes I define like so:

routes.rb ->

map.seo "/pages/:id/:permalink", :controller => "pages", :action => "show"

Below is the error message I am getting. Apparently the diff is the id, although I don't know why.

Update:

I am getting this as my error:

seo_url failed to generate from {:controller=>"pages", :id=>"45", :action=>"show"}, expected: {:controller=>"pages", :action=>"show"}, diff: {:id=>"45"}
Betsy
  • 25
  • 4

2 Answers2

2

Why not using the to_param method?

class YourModel << AR::Base

 def to_param
    "#{id}-#{title.parameterize}"
 end

Thus getting routes like

/pages/1-here-is-my-converted-article-title-to-permalink

Besides that, it would seems Rails isn't recognizing your route. Have you restarted your web server? Try sending only a :permalink attribute to see how it goes.

Alessandra Pereyra
  • 2,640
  • 18
  • 22
0

I don't fully understand your question.

It looks like id is already specified in your named route, and in your view. It looks like you need to also specify permalink in your view. Are you getting an error?

theIV
  • 25,434
  • 5
  • 54
  • 58
  • Sorry should clarify on that - It is specified on the view side but, not in my routes file. See the above update with the error message. I appreciate your help theIV! – Betsy Sep 25 '09 at 16:50
  • @Betsy, this is the part that confuses me: "However in my named route in routes.rb, I need to specify :id => something here." What do you mean by "need to specify". Are you not trying to have the id and permalink refer to the same object and are doing this for pretty urls purposes? – theIV Sep 25 '09 at 18:19
  • Actually that was my just bad suggestion. I am going to remove it. Basically my problem is the error message. I would like to have /pages/1/here_is_my_converted_article_title_to_permalink. – Betsy Sep 26 '09 at 15:40