2016-04-02 12 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 

は基本的に私が達成しようとしているものです:ユーザーがリンクをクリックすると、彼は元のポスターのプロフィールページへ

リダイレクトされます。例:はlocalhost: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 

ルート:あなたは文字列に手動でIDをキャストする必要が

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

= 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}" 
関連する問題