【发布时间】:2016-04-06 17:19:01
【问题描述】:
我收到此错误:未定义的局部变量或方法 `user' for # 指向配置文件控制器第 9 行,“def 更新方法后的第一行”顺便说一句,我正在为我的用户使用设计。
class ProfileController < ApplicationController
before_action :authenticate_user!
def index
@user = current_user
end
def update
current_user.update(user.params)
redirect_to root_path
end
private
def user_params
params.require(user).permit(:first_name, :last_name)
end
end
这是我的 application.html.erb,我的编辑器“Rubymine”告诉我 user_signed_in?、current_user、destroy_user_session_path、new_user_session_path 和 new_user_registration_path 找不到
<!DOCTYPE html>
<html>
<head>
<title>TwitterClone</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<%= csrf_meta_tags %>
</head>
<body>
<div class="right">
<% if user_signed_in? %>
Welcome <%= current_user.display_name %>,
<%= link_to "Logout", destroy_user_session_path, method: "DELETE" %>
<% else %>
Please
<%= link_to "Login", new_user_session_path %>
or
<%= link_to "Signup", new_user_registration_path %>
<% end %>
</div>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>
我的路线是 Devise 为用户生成的路线以及我为 Profile 生成的路线:
profile GET /profile(.:format) profile#index
PATCH /profile(.:format) profile#update
这是设计生成的架构:
ActiveRecord::Schema.define(version: 20160406005549) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "first_name"
t.string "last_name"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
【问题讨论】:
-
user.params应该是user_params
标签: ruby-on-rails ruby devise