我跟着一個rails 3教程,我試圖讓這個工作正常。如何顯示個別微博的鏈接? (在軌道3上的紅寶石)
,用戶提出的是在http://localhost:3000/users/username
UsersController中列出的所有微柱
def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate page: params[:page], :per_page => 15
end
每個微柱都有一個ID
create_table "microposts", :force => true do |t|
t.text "content"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image"
t.text "comment_content"
end
我如何設定,讓這樣的鏈接http://localhost:3000/users/username/micropost_id
(如果有效)將導致只有該微博的頁面?
我希望顯示完全一樣,除了在新頁面上單獨顯示。
用戶表
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
end
我的配置路線
MyApp::Application.routes.draw do
resources :authentications
resources :microposts, :path => "posts"
root to: 'static_pages#home'
ActiveAdmin.routes(self)
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:new, :create, :destroy]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
resources :microposts do
resources :postcomments
end
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/post', to: 'static_pages#post'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/users/:username/:id', to: 'microposts#show', via: :get, as: :user_micropost
end
你可以發佈你的'config/routes'嗎? – everett1992
posted routes.rb – nextstep