ユーザーがサインアップすると(つまり、新しいユーザーが作成されると)、チュートリアルにリダイレクトされるようにしようとしています。ただし、ユーザーがサインアップすると、ユーザー名と電子メールは一意である必要があるというエラー メッセージが表示され (一意であっても)、「新しい」ページが再度表示されます。
代わりにリダイレクトすると、これは正常に機能し@user
ます。
これは私のコントローラーです:
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
login(@user)
format.html { redirect_to "static/tutorial", success: 'Congratulations on starting your journey!' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
そして、これらは User.rb の関連する行です:
validates_confirmation_of :plain_password
validates_presence_of :name, :username, :email
validates_presence_of :plain_password, :on => :create
validates_uniqueness_of :email, :username