編集をクリックすると、次のように表示されます: フォームの最初の引数に nil を含めることはできません。
ユーザー/_form
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %>
prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :name, "Username" %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :email %><br />
<%= f.text_field :email %>
</p>
<p>
<%= f.label :password %><br />
<%= f.password_field :password %>
</p>
<p>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</p>
<% if @user.new_record? %>
<%= f.submit "Sign up" %>
<% else %>
<%= f.submit "Update Profile" %>
<% end %>
<% end %>
users_controllerで
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
flash[:notice] = "You have signed up successfully."
redirect_to posts_path
else
render :new
end
end
def show
@user=User.find(params[:id])
end
def update
if @user.update(user_params)
flash[:notice] = "Profile has been updated"
redirect_to @user
else
flash[:alert] = "Profile has not been updated"
render 'edit'
end
end
def edit
end
def destroy
@user = User.find(params[:id])
@user.destroy
flash[:notice] = "Post has been destroyed."
redirect_to posts_path
end
private
def user_params
params.require(:user).permit(:name,:password,:password_confirmation, :email)
end
end
モデルユーザーで
class User < ActiveRecord::Base
has_secure_password
end
ビュー/編集中
<h2>Edit Profile</h2>
<%= render 'form' %>
ビュー/ショーで
<h1>Profile Page for <%= @user.name %></h1>
<p>Email: <%= @user.email %></p>
<p><%= link_to "Edit Profile", edit_user_path(@user) %></p>
<%= link_to "Delete Profile",user_path(@user),method: :delete,
data: { confirm:"Are you sure you want to delete this post?"} %>
何が問題で、どうすれば修正できますか? PS:レール4です