【发布时间】:2015-03-14 16:18:18
【问题描述】:
Michael Hartl 编写的通过 Rails 教程第 3 版工作:第 8 章登录、注销
我需要帮助理解为什么在 session_controller 中我们使用常规的“用户”变量,而在 users_controller 中我们使用“@user”实例变量。
我注意到在 session_controller 中,我们使用了
def create
user = User.find_by...
而在 users_controller 中,我们使用
def create
@user = User.new...
Michael 指出,“会话表单和注册表单之间的主要区别在于我们没有会话模型,因此没有 @user 变量的类似物......”指的是:
form_for(@user)
从用户角度对比
form_for(:session, url: login_path)
从会话视图。
这有关系吗?我仍然不明白这一点。如果我需要更清楚或更具体,请告诉我。谢谢!
【问题讨论】:
标签: ruby-on-rails ruby session