Permalink-fu - Display URL differently
I'm using Ruby on Rails 2.3.8 and permalink-fu plugin. I would like to know how to generate permalinks like this: /posts/4444开发者_开发知识库4/this-is-the-title
instead of /posts/44444-this-is-the-title
I've tried modifying my Post
model as follows:
has_permalink :title, :update => true
def to_param
"#{permalink}"
end
And my routes file as follows:
map.show "/posts/:id/:permalink", :controller => 'posts', :action => 'show'
Then, if I manually type the url with that format, it will work, but if I make a link out of a post in my view as follows, it wont generate the link formatted that way:
<%= link_to p.title, p %>
Where p
represents a post.
How can I do so when I call a post like that, I get a permalink formatted as /posts/:id/:permalink
instead of /posts/:id-:permalink
?
Try this one...
on model:
def to_params
[self.id, self.permalink]
end
on views:
<%= link_to p.title, show_path(p) %>
精彩评论