アプリで新しいユーザーが作成されたときに、すべてが既に設定されているようにしようとしています。たとえば、メモを保存するフォルダがあります。したがって、新しいフォルダへのリンクをクリックしてから送信ボタンをクリックしてメモを保存するのではなく、メモを保存する前に、ユーザーアカウントの作成時に自動的に設定することはできますか?
例えば
users_controller.rb:
def create
@user.password = params[:password]
respond_to do |format|
if @user.save
@folder = @user.folder.new(params[:folder]) # this is the line that I'm unsure how to implement
format.html { redirect_to @user, notice: 'User was successfully created.' }
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
解決:
Deviseを使用しているときに、ユーザーコントローラーに追加していたルーティングが上書きされていたため、解決策(おそらくこれを行うためのより良い方法があります!)は、登録コントローラーのafter_user_sign_up_pathにコードを追加することでした。 。