views:

141

answers:

2

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"}
A: 

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
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
@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
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
+1  A: 

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.

Yaraher
+1 for the hint on `to_param`
Thomas