My controller code is like these:
def edit
@user = User.find params[:id]
end
def update
@user = User.find params[:id]
if @user.update_attributes(params[:user])
flash[:notice] = "success!"
else
flash[:notice] = "fail!"
end
end
attr_accessor :username, :introduction, :first_name, :last_name
private
def user_params
params.require(:user).permit(:username, :introduction, :first_name, :last_name)
end
View:
<%= form_for @user, :url =>edit_path(@user), :method => :PUT do |f| %>
<%= f.label :username %><br>
<%= f.text_field :username %>
<br>
<%= f.label :Introduction %><br>
<%= f.text_area :introduction %>
<br>
<%= f.label :FirstName %><br>
<%= f.text_field :first_name %>
<br>
<%= f.label :LastName %><br>
<%= f.text_field :last_name %>
<br>
<%= f.submit "Save changes"%><% end %>
And the terminal is:
Started PUT "/profile/1/edit" for 127.0.0.1 at 2017-12-06 04:30:05 -0500 Processing by ProfileController#edit as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"eBvvAG892DTOFzYuFTKPCgbOuSQXB8BVOub7A8CgaPHLW2vaBFMpUGNHhgYZednfd5pqICCy1DykIarD7QYtIg==", "user"=>{"username"=>"aaa", "introduction"=>"aaaaa", "first_name"=>"a", "last_name"=>"a"}, "commit"=>"Save changes", "id"=>"1"} User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]] Notification Load (0.1ms) SELECT "notifications".* FROM "notifications" Chat Exists (0.0ms) SELECT 1 AS one FROM "chats" WHERE "chats"."sender_id" = ? LIMIT 1 [["sender_id", 1]] Chat Exists (0.0ms) SELECT 1 AS one FROM "chats" WHERE "chats"."recip_id" = ? LIMIT 1 [["recip_id", 1]] User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "1"]] Rendered profile/edit.html.erb within layouts/game (1.5ms) User Load (0.2ms) SELECT "users".* FROM "users" Completed 200 OK in 32ms (Views: 28.5ms | ActiveRecord: 0.5ms)
But database is not updating:
1|[email protected]|$2a$11$2WHUjqQHU1gtlzw3ObXgVeE7dGG1qby2tLmATeoUyMnh1cg5wXv86||||3|2017-12-06 08:43:44.469588|2017-12-06 05:32:19.252680|127.0.0.1|127.0.0.1|2017-12-05 17:04:39.689636|2017-12-06 08:43:44.470487||1970-1-1|||This guy is lazy. Without an Introduction.|