Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何从零开始将用户配置文件更新为用户身份验证_Ruby On Rails - Fatal编程技术网

Ruby on rails 如何从零开始将用户配置文件更新为用户身份验证

Ruby on rails 如何从零开始将用户配置文件更新为用户身份验证,ruby-on-rails,Ruby On Rails,我从零开始就遵循修订后的Railscast进行用户身份验证 我想知道我如何才能添加部分供用户修改个人资料,因为我有其他字段,他们需要在注册后输入,如性别、种族、职业、关于我、孩子、身高等 有没有一个教程告诉你怎么做,或者有人能帮我指出正确的方向 可以在以下位置查看我的项目文件: 更新 我已经开始工作了,不确定我是否做对了。我希望用户能够修改他们的帐户设置(注册时使用的字段) 下面是/users文件夹中的my edit.html <h1>Account Information</

我从零开始就遵循修订后的Railscast进行用户身份验证

我想知道我如何才能添加部分供用户修改个人资料,因为我有其他字段,他们需要在注册后输入,如性别、种族、职业、关于我、孩子、身高等

有没有一个教程告诉你怎么做,或者有人能帮我指出正确的方向

可以在以下位置查看我的项目文件:

更新

我已经开始工作了,不确定我是否做对了。我希望用户能够修改他们的帐户设置(注册时使用的字段)

下面是/users文件夹中的my edit.html

<h1>Account Information</h1>

<%= form_for @user do |f| %>
  <% if @user.errors.any? %>
    <div class="error_messages">
      <h2>Form is invalid</h2>
      <ul>
        <% @user.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

    <div class="field">
        <%= f.label :email %><br/>
        <%= f.text_field :email %>
    </div>
    <div class="field">
        <%= f.label :password %><br/>
        <%= f.password_field :password %>
    </div>
    <div class="field">
        <%= f.label :password_confirmation %><br/>
        <%= f.password_field :password_confirmation %>
    </div>
    <div class="field">
        <%= f.label :username %><br/>
        <%= f.text_field :username %>
    </div>
    <div class="field">
        <%= f.label :zip_code %><br/>
        <%= f.text_field :zip_code %>
    </div>
    <div class="field">
        <%= f.label :birthday %><br/>
        <%= f.text_field :birthday %>
    </div>  
    <div class="actions"><%= f.submit %></div>
<% end %>
以下是我添加到users\u controller的内容,我不确定我是否正确添加了这些内容:

  def edit
      @user = User.find(params[:user])
  end

  def update
    @user = User.find(params[:user])
    if @user.update_attributes(params[:user])
      flash[:success] = "Account updated"
      sign_in @user
      redirect_to @user
    else
      render 'edit'
  end

我最终如何让一切正常工作是用户将转到/编辑以修改他们的帐户设置以及注册期间填写的所有私人信息。然后用户可以直接在他们的个人资料页面上编辑个人资料信息(性别、种族、职业、关于我的信息等)(将使用就地编辑)。因此,我只需要知道我所采取的步骤是否正确(我还没有使用终端),如果正确,我如何让编辑页面显示为显示路由错误atm。

只是一些常规指针

在Railscasts中,正在创建
用户\u控制器
新建
创建
操作。您希望编辑一个用户,因此可以构建此控制器的
edit
update
操作

# app/controllers/users_controller.rb
class UsersController < ...
  def new
    # exists
  end

  def create
    # exists
  end

  def edit
    # load the current_user; make sure a user can only edit his record!
  end

  def update
    # save edit for the current_user, same security as above
  end
end
#app/controllers/users_controller.rb
类UsersController<。。。
def新
#存在
结束
def创建
#存在
结束
定义编辑
#加载当前用户;确保用户只能编辑其记录!
结束
def更新
#为当前用户保存编辑,安全性与上述相同
结束
结束

在您的路线中,您可以了解如何将
资源:配置文件
单一资源路线映射到相应的操作。

修订的railscasts无法公开访问,请向我们展示一些代码。在此基础上,我们可以提出一些建议,我添加了github链接来显示所有文件。这应该会有帮助,谢谢我更新了我的帖子,我已经做了。但我不确定我走的方向是否正确。
# app/controllers/users_controller.rb
class UsersController < ...
  def new
    # exists
  end

  def create
    # exists
  end

  def edit
    # load the current_user; make sure a user can only edit his record!
  end

  def update
    # save edit for the current_user, same security as above
  end
end