【问题标题】:Custom Profile Edit Page. Devise Gem自定义配置文件编辑页面。设计宝石
【发布时间】:2014-06-30 23:03:31
【问题描述】:

我是 Rails 新手。 我的应用程序中有一个注册页面。还有个人资料页面。我正在尝试制作一个编辑页面,我可以在其中编辑用户的电子邮件、密码和所有内容。我想用设计来做这一切.. 我已经达到了。这是我的编辑页面。

<div class="edit_profile_page">
<%= form_for(current_user, :url => '/update', :html => { :method => :put }) do |f| %>

  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>

  <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
  <%= f.password_field :password, :autocomplete => "off" %></div>

  <div><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></div>

  <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
  <%= f.password_field :current_password %></div>

  <div><%= f.submit "Update" %></div>
<% end %>
</div>

我被困在这里了。我应该通过什么 url.. 另外如果这个 url 指向一个方法说

def update_profile
end

我应该在该方法中写什么,以便密码会像注册时那样更新。

或者

Device里面有一个编辑页面。我应该如何编写到达那里的路线。

【问题讨论】:

  • 你添加到路由了吗?
  • 是的..我已经完成了所有基本的事情..实际上我不知道如何通过设计进行此操作
  • update_profile 是提交表单的方法?
  • 我不知道在哪里提交它..这就是我所说的..我不知道如何继续。

标签: ruby-on-rails ruby ruby-on-rails-4 devise


【解决方案1】:

您也可以创建自己的ProfilesController,示例如下:

路线:

#routes.rb
resource :profile

控制器:

# coding: utf-8
class ProfilesController < ApplicationController
  before_filter :authenticate_user!

  def show
    @user=current_user
    @user.email = nil unless @user.email.scan('@example.com').empty?
    render 'devise/profile/edit'
  end

  def update
    @user=current_user
    if @user.update_attributes(params[:user])
        sign_in 'user', @user, :bypass => true
        flash[:notice] = t('users.profile.edit.updated')
        respond_to do |format|
            format.html { redirect_to '/'}
        end
    else
      render 'devise/profile/edit'
    end
  end
end

观看次数

#views/devise/profile/edit.html.haml
%h3
  = t('users.profile.basic_settings')
= simple_form_for @user, :url => profile_path, :html => { :method => :put } do |f|
  -#= f.error_messages
  = f.input :name, :placeholder=>t('activerecord.placeholders.name')
  = f.input :email, :placeholder=>t('activerecord.placeholders.email')
  = f.submit t('users.profile.change_name'), :class => "btn btn-primary"


  = t('users.profile.change_password')
= simple_form_for @user, :url => profile_path, :html => { :method => :put } do |f|
  -#= f.error_messages

  = f.input :password , :error_html => { :id => "password_error"}
  = f.input :password_confirmation
  = f.submit t('users.profile.change_password'), :class => "btn btn-primary"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多