【发布时间】:2016-04-02 23:38:50
【问题描述】:
如何链接到用户的个人资料视图而不出现no implicit conversion of Fixnum into String 错误?
我目前拥有的:
- @questions.each do |question|
= link_to question.user.username, "/users/"+question.user.id
基本上我想要实现的是:
当用户点击链接时,他将被重定向到原始发帖者的个人资料页面。例如:localhost:3000/users/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 "/users/:id" => "home#profile"
get "home" => "home#feed"
get "questions" => "home#questions"
resources :questions
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4