私のプロファイルモデルを真のwelcome_controllerに更新しようとしています。この理由は、ユーザーが最初のプロファイルを作成する場合に、ウェルカム ウィザードとしていくつかの手順があるためです。
IDを提供していないため、ルーティングを正しく取得できません。
- welcome#edit/ :step は正しいステップを読み込みます
- welcome#update は、プロファイル属性を更新し、それがオンになっているステップを保存する必要があります (合計 3 つのステップ)
ルート.rb
match "/welcome/:step" => "welcome#edit"
match "/welcome" => "welcome#edit"
resources :welcome
welcome_controller の更新および編集アクション:
def edit
# form updates post to edit since
# profile is non existant yet
params[:step] = "photos" unless params[:step]
@photos = Photo.where(:attachable_id => current_user.id)
@profile = Profile.where(:user_id => current_user.id).first
@photo = Photo.new
if ["photos", "basics", "details"].member?(params[:step])
render :template => "/profiles/edit/edit_#{ params[:step]}", :layout => "welcome"
else
render :action => "/profiles/edit_photos"
end
end
# update profile attributes then update the correct step
def update
raise('welcome update called')
@profile = Profile.where(:user_id => current_user.id).first
@profile.update_attributes(params[:profile])
case params[:step] # update the steps
when "photos"
current_user.update_attributes(:welcome => 1)
when "basics"
current_user.update_attributes(:welcome => 2)
when "details"
current_user.update_attributes(:welcome => 3)
end
# redirect to welcome_path before_filter determine step
redirect_to welcome_path
end
写真、基本、詳細のフォームは @profile の form_for にすぎないので、プロファイルに投稿しますが、代わりにウェルカムコントローラーに投稿したいと思います:(
これにアプローチする最良の方法は何ですか? これに完全に行き詰まった