Skip to content

Instantly share code, notes, and snippets.

@tienshunlo
Created June 16, 2016 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tienshunlo/0abe9af001b0c690fef008e4732f67fd to your computer and use it in GitHub Desktop.
Save tienshunlo/0abe9af001b0c690fef008e4732f67fd to your computer and use it in GitHub Desktop.
更新profile的題目
def update
@profile = @user.profile
ids = @profile.profile_option.map{|t| t.option_id}
if ids.length > 0
ProfileOption.where("profile_id =? AND option_id NOT IN (#{ids.join(',')})", @profile.id).delete_all
else
ProfileOption.where("profile_id = ?", @profile.id).delete_all
end
@profile.profile_option.each_pair do |id , data|
ic = ProfileOption.where(:profile_id => @profile.id, :id => id).first
if ic
ic.update_attributes(:option_id => data[:option_id])
end
end
params[:profile][:profile_option][][:option_id].each_index do |index|
ProfileOption.create(:profile_id => @profile.id, :option_id => params[:profile][:profile_option][][:option_id][index])
end
redirect_to dashboard_user_path(current_user)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment