Reputation: 15501
Im trying to update my profile model true a welcome_controller. The reason for this is that I have some steps as a welcome wizzard were the user builds his initial profile.
I cannot get the routing correct, since im not supplying an id.
routes.rb
match "/welcome/:step" => "welcome#edit"
match "/welcome" => "welcome#edit"
resources :welcome
welcome_controller update and edit actions:
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
the forms for photo, basic and details are just a form_for @profile So im posting it to profile but want to post it to the welcome controller instead :(
Whats the best way to approach this ? Totally stuck on this
Upvotes: 0
Views: 228
Reputation: 12564
There are a couple of approaches available to this problem.
Upvotes: 1