【发布时间】:2014-03-18 22:59:54
【问题描述】:
首先对不起我的英语
我正在使用 Friendly_id gem 来创建 Clean URL,它工作得很好,但是我想要一个像 http://localhost:3000/profile/jack-sparo 这样的 URL,而不是像这样的 URL http://localhost:3000/profile/1/jack-sparo其中 1 是 user_id,那么我该怎么做呢?
这是我的配置/路线
get "profiles/show"
get '/profile/:id' => 'profiles#show', :as => :profile
get 'profiles' => 'profiles#index'
这是我的个人资料控制器
def show
@user= User.find_by_slug(params[:id])
if @user
@posts= Post.all
render action: :show
else
render file: 'public/404', status: 404, formats: [:html]
end
end
【问题讨论】:
-
发布你的 config/routes.rb 我可以给你确切的代码,不过这取决于你当前的路线。
标签: ruby-on-rails ruby friendly-url friendly-id