Created
March 4, 2018 12:37
-
-
Save WolfpackGaming-SavSin/8184e3f6a838c4bf9045815e6d20c59f to your computer and use it in GitHub Desktop.
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
# app/models/user.rb | |
has_settings :user_show_settings, :user_settings | |
# app/views/users/edit_profile.html.erb | |
<div align="center"> | |
<%= form_tag update_profile_path, method: :post do %> | |
<div class="form-group row no-padding text-center col-md-12"> | |
<div class="col-md-10 profile-edit"> | |
<strong> Birthday: </strong> | |
<%= text_field_tag :birthday, params[:birthday], placeholder: "Enter your birthday: YYYY-MM-DD", autofocus: true, value: @user.settings(:user_settings).birthday, class: 'form-control search-box input-sm' %> | |
<strong> Website: </strong> | |
<%= text_field_tag :website, params[:website], placeholder: "Enter your Website", value: @user.settings(:user_settings).website, class: 'form-control search-box input-lg' %> | |
<strong> Bio: </strong> | |
<%= text_area_tag :bio, @user.settings(:user_settings).bio, class: 'form-control search-box input-lg' %> | |
<table> | |
<tr> | |
<th class="profile-cell">Option</th> | |
<th class="profile-cell">Show</th> | |
<th class="profile-cell">Hide</th> | |
</tr> | |
<tr> | |
<td class="profile-cell">Full Name</td> | |
<td class="profile-cell"><%= radio_button_tag("show_name", true, @user.settings(:user_show_settings).show_name) %></td> | |
<td class="profile-cell"><%= radio_button_tag("show_name", false, (true unless @user.settings(:user_show_settings).show_name)) %></td> | |
</tr> | |
<tr> | |
<td class="profile-cell">E-Mail</td> | |
<td class="profile-cell"><%= radio_button_tag("show_email", true, @user.settings(:user_show_settings).show_email) %></td> | |
<td class="profile-cell"><%= radio_button_tag("show_email", false, (true unless @user.settings(:user_show_settings).show_email)) %></td> | |
</tr> | |
<tr> | |
<td class="profile-cell">Birthday</td> | |
<td class="profile-cell"><%= radio_button_tag("show_birthday", true, @user.settings(:user_show_settings).show_birthday) %></td> | |
<td class="profile-cell"><%= radio_button_tag("show_birthday", false, (true unless @user.settings(:user_show_settings).show_birthday)) %></td> | |
</tr> | |
<tr> | |
<td class="profile-cell">Website</td> | |
<td class="profile-cell"><%= radio_button_tag("show_website", true, @user.settings(:user_show_settings).show_website) %></td> | |
<td class="profile-cell"><%= radio_button_tag("show_website", false, (true unless @user.settings(:user_show_settings).show_website)) %></td> | |
</tr> | |
</table> | |
<br /> | |
<%= button_tag('Update Profile', type: :submit, class: "btn btn-lg btn-success") %> | |
</div> | |
</div> | |
<% end %> | |
</div> | |
# app/controllers/user_controller.rb | |
def update_profile | |
byebug # Shows permitted = false | |
current_user.settings(:user_settings).birthday = params[:birthday] | |
current_user.settings(:user_settings).website = params[:website] | |
current_user.settings(:user_settings).bio = params[:bio] | |
current_user.settings(:user_show_settings).show_name = params[:show_name] | |
current_user.settings(:user_show_settings).show_email = params[:show_email] | |
current_user.settings(:user_show_settings).show_birthday = params[:show_birthday] | |
current_user.settings(:user_show_settings).show_website = params[:show_website] | |
if current_user.save() | |
flash[:success] = "Profile Updated Successfully" | |
redirect_to user_path(current_user) | |
else | |
redirect_to edit_profile_path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment