Created
March 14, 2012 18:11
-
-
Save reignmaker/2038323 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <%= semantic_form_for user do |f| %> | |
| <%= f.inputs "User" do %> | |
| <%= f.input :name %> | |
| <%= f.input :email %> | |
| <label for="change_password" class="checkbox"> | |
| <input type="checkbox" name="change_password" id="change_password"> | |
| Change password? | |
| </label> | |
| <%= f.input :password %> | |
| <%= f.input :password_confirmation %> | |
| <%= f.input :sex %> | |
| <%= f.input :about %> | |
| <%= f.input :birthday %> | |
| <%= f.input :skype %> | |
| <%= f.input :facebook %> | |
| <%= f.input :twitter %> | |
| <% end -%> | |
| <%= f.buttons %> | |
| <% end -%> |
This file contains hidden or 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
| <p><%= user.email %></p> | |
| <p><%= user.name %></p> | |
| <p><%= user.about %></p> | |
| <p><%= user.birthday %></p> | |
| <%= link_to "Edit profile", edit_user_path(user) %> |
This file contains hidden or 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
| <%= render 'form', :user => @user %> |
This file contains hidden or 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
| devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks", :registrations => "registrations" } #do | |
| resources :users, :only => [:show, :edit, :update] # users роут должен быть обязательно после devise |
This file contains hidden or 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
| <%= render 'user', :user => @user %> |
This file contains hidden or 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
| <%= render 'user', :user => @user %> |
This file contains hidden or 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
| class UsersController < ApplicationController | |
| respond_to :html | |
| def show | |
| @user = current_user | |
| end | |
| def edit | |
| @user = User.find(current_user.id) | |
| end | |
| def update | |
| @user = current_user | |
| if params['change_password'] # проверяем, если пользователь хочет сменить пароль | |
| if @user.update_with_password(params[:user]) # вспомогательные методы devise'а | |
| sign_in @user, :bypass => true # авторизуем пользователя после обновления | |
| respond_with @user | |
| else | |
| render "edit" | |
| end | |
| else | |
| if @user.update_without_password(params[:user]) # обновлаем аттрибуты без пароля | |
| sign_in @user, :bypass => true | |
| respond_with @user | |
| else | |
| render "edit" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Там ещё надо было поле current_password поставить, без него update_with_password не работает