小编Kas*_*ask的帖子

Railstutorial.org Michael Hartl第9章练习3"不应该允许通过网络编辑admin属性"

我已经开始学习Rails了,而且我第9章第三次练习了.

该演习看起来是这样的:

  test "should not allow the admin attribute to be edited via the web" do
    log_in_as(@other_user)
    assert_not @other_user.admin?
    patch :update, id: @other_user, user: { password:              FILL_IN,
                                            password_confirmation: FILL_IN,
                                            admin: FILL_IN }
    assert_not @other_user.FILL_IN.admin?
  end
Run Code Online (Sandbox Code Playgroud)

我的问题是last Fill_IN >> assert_not @other_user.FILL_IN.admin?

@other_user 取自Fixture,看起来像这样:

archer:
  name: Sterling Archer
  email: duchess@example.gov
  password_digest: <%= User.digest('password') %>
Run Code Online (Sandbox Code Playgroud)

Update action 看起来像这样:

  def update
    @user = User.find(params[:id])
    if @user.update_attributes(user_params)
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end
Run Code Online (Sandbox Code Playgroud)

我还添加:admin到user_params所以 …

ruby-on-rails railstutorial.org

4
推荐指数
2
解决办法
2926
查看次数

标签 统计

railstutorial.org ×1

ruby-on-rails ×1