开发者

Replacing :id from routes without breaking the convention

开发者 https://www.devze.com 2023-02-14 03:40 出处:网络
I just replaced the :id on the resource routes in rails 3 for a hash genera开发者_如何学JAVAted. I\'m annoyed by the fact that I\'m writing less conventional code (e.g. a link_to edit_user_path(@user)

I just replaced the :id on the resource routes in rails 3 for a hash genera开发者_如何学JAVAted. I'm annoyed by the fact that I'm writing less conventional code (e.g. a link_to edit_user_path(@user) is now written as link_to '/users/#{@user.user_hash}'). So I'm wondering, is therea smarter way to do this?


class User < ActiveRecord::Base
  def to_param
    user_hash
  end
end

and edit_user_path(@user) will work properly for you

0

精彩评论

暂无评论...
验证码 换一张
取 消