Created
June 16, 2016 14:12
-
-
Save tienshunlo/0abe9af001b0c690fef008e4732f67fd to your computer and use it in GitHub Desktop.
更新profile的題目
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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