2016-04-02 45 views
1

如何鏈接到用戶的配置文件視圖,但沒有得到no implicit conversion of Fixnum into String錯誤?鏈接到用戶的配置文件視圖

我目前有:

- @questions.each do |question| 
    = link_to question.user.username, "https://stackoverflow.com/users/"+question.user.id 

基本上我想實現的是:

當用戶點擊一個鏈接時,他將被重定向到原來的海報的資料頁。例如:本地主機:3000 /用戶/ 1

首頁控制器:

def profile 
    if !user_signed_in? 
     redirect_to new_user_session_path 
    end 
    if User.find_by_id(params[:id]) 
     @user = User.find(params[:id]) 
    else 
     redirect_to root_path 
    end 
    end 

路線:

Rails.application.routes.draw do 
    root 'home#home' 
    devise_for :users 
    get "https://stackoverflow.com/users/:id" => "home#profile" 
    get "home" => "home#feed" 
    get "questions" => "home#questions" 
    resources :questions 
end 

回答

2

您需要手動施放ID字符串:

= link_to question.user.username, "https://stackoverflow.com/users/"+question.user.id.to_s 

我希望有幫助。

1

另外這個應該工作。

= link_to question.user.username, "https://stackoverflow.com/users/#{question.user.id}" 
相關問題