如何在 rails 中为用户仪表板使用参数
How to use params for user dashboard in rails
我对参数有疑问:
如何在我的控制器中过滤每个用户的显示。
在我的模型中
user.rb:
has_many: questions
question.rb
belongs_to: user
控制器:
` skip_before_action :authenticate_user!, 只有: [ :new ]
before_action :find_question, 仅: [:show, :edit, :update, :destroy]
def index
@questions = Questions.all
end
private
def find_question
@question = Question.find(params[:id])
end`
没关系
我的解决方法很简单....
创建 users_controller 具有:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@questions = @user.questions
end
end
和
users.html.erb 与:
<% @questions.each do |question| %>
bla,bla,bla,bla
<% end %>
感谢您的宝贵时间。
我对参数有疑问:
如何在我的控制器中过滤每个用户的显示。
在我的模型中
user.rb:
has_many: questions
question.rb
belongs_to: user
控制器:
` skip_before_action :authenticate_user!, 只有: [ :new ] before_action :find_question, 仅: [:show, :edit, :update, :destroy]
def index
@questions = Questions.all
end
private
def find_question
@question = Question.find(params[:id])
end`
没关系
我的解决方法很简单....
创建 users_controller 具有:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@questions = @user.questions
end
end
和
users.html.erb 与:
<% @questions.each do |question| %>
bla,bla,bla,bla
<% end %>
感谢您的宝贵时间。