對於我的rails應用程序,我試圖爲我的用戶創建一個隨機固定鏈接,以便它不是localhost:3000/users /:id,而是localhost:3000/users/permalink。Rails - 如何爲永久鏈接的用戶路由?
我按照崗位上做出了這裏: how to make ID a random 8 digit alphanumeric in rails?
繼後,我已經能夠創建爲我的用戶隨機永久鏈接欄和頁面,但一直沒能得到子頁面,工作。爲我的用戶,我現在有子頁面:關注等
問題:目前該頁面被路由到本地主機:3000 /用戶/ :id
/追隨者等,但沒有人知道如何解決途徑。 RB,這樣我也可以使這些頁面爲localhost:3000 /用戶/ permalink
/追隨者等
的routes.rb
match 'users/:permalink' => 'users#show', :as => "show_user"
resources :users do
member do
get :followers
end
end
user.rb
attr_accessible :permalink
before_create :make_it_permalink
def make_it_permalink
self.permalink = SecureRandom.base64(8)
end
users_controller.rb
def show
@user = User.find_by_permalink(params[:permalink])
end
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers.page(params[:page]).per_page(5)
render 'show_follow'
end
用戶/ _header.html.erb
<%= render 'users/followerstats' %>
用戶/ _followerstats.html.erb
<a href = "<%= followers_user_path(@user) %>">
My Followers (<%= @user.followers.count %>)
</a>
用戶/ show_follow.html.erb
<div class = "container">
<%= render 'header' %>
<% provide(:title, @title) %>
<div class="row">
<div class="span12">
<h4><%= @title %></h4>
<% if @users.any? %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate %>
<% end %>
/div>
</div>
永久性聽起來像它只是一個不同的ID。你爲什麼需要這個? – 2013-05-06 03:25:58