私のレールアプリには何か変なことがあります。フォーマットが間違っていると、特定のページにユーザーをリダイレクトしようとします。それは動作しますが、URLがビューに一致しません。rails - URLが表示と一致しません
私はrails g scaffold User
によって生成されたファイルを使用します。モデルファイルに特定の条件を追加して、ユーザー入力をチェックしてフォームの形式が正しいかどうかを確認し、そうでない場合は接続ビューにリダイレクトします。この中
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to root_path, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
:
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to root_path, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :template => 'pages/connection' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
私が試した
私はので、私はこの(アプリ/コントローラ/ users_controller.rbを)回し2つの異なるコントローラ
の間に彼をリダイレクト私はよくページ/ connection.rbにリダイレクトされますが、私のブラウザのURLはですで、http://url:8080/connection
ではありません。ですから、リフレッシュすると、ページ/ connection.rb〜ユーザー/のままになります。
また、/user.rbのエラーメッセージは表示されません。
私のコードで何が間違っていますか?
同じではありませんレンダリングとリダイレクト - あなたはあなたのビューでそれらを一覧表示しようとしていますか? – max
実際に私はscaffoldで作成したファイルからいくつかのコンテンツを貼り付けてコピーします。私はuser.errors.full_messagesをコピーすることを忘れました – Tellimi