Ruby on rails 3 Rails 3:如何从设计中拉出更改密码为其自己的独立形式

Ruby on rails 3 Rails 3:如何从设计中拉出更改密码为其自己的独立形式,ruby-on-rails-3,forms,devise,Ruby On Rails 3,Forms,Devise,我正在使用Desive进行用户注册,我希望有一个单独的编辑路径供用户更改/更新密码。我已经拉出了Desive registrations视图,并创建了一个单独的注册控制器,如中所述 我尝试在注册控制器中创建一个名为change_password的新操作,但当我尝试使用匹配“/change_password”将路由设置为=>“registrations#change_password”时,我得到一个AbstractController::Actions Not Found 注册管理员 查看/注册/

我正在使用Desive进行用户注册,我希望有一个单独的编辑路径供用户更改/更新密码。我已经拉出了Desive registrations视图,并创建了一个单独的注册控制器,如中所述

我尝试在注册控制器中创建一个名为change_password的新操作,但当我尝试使用匹配“/change_password”将路由设置为=>“registrations#change_password”时,我得到一个AbstractController::Actions Not Found

注册管理员 查看/注册/更改密码.html.erb
编辑
资源名称:url=>注册路径(资源名称),:validate=>true,
:html=>{:method=>:put},:html=>{:multipart=>true})do | f |%>
更改密码,否则留空。

(如果不想更改,请留空)





尝试在帮助程序的designe\u块中传递
匹配..

devise_for :users, :controllers => {:registrations => 'registrations'} do
  match '/change_password', to => 'registrations#change_password'
end

尝试传递帮助程序的designe_块中的
match..

devise_for :users, :controllers => {:registrations => 'registrations'} do
  match '/change_password', to => 'registrations#change_password'
end

我发现这是将用户编辑表单拆分为编辑和帐户的最简单方法

原来我有

:name, 
:email, 
:avatar, 
:location, 
:website, 
:bio,  
:password (all in one form)
路线(这提供了路线: 账户_用户获取/users/:id/账户(:格式)用户#账户)

用户\u CONTROLLER.RB

before_filter :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers, :account]
before_filter :correct_user,   only: [:edit, :update, :account]


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

def account
  @title = "Account"
  @user = User.find(params[:id])
end

def update
  if @user.update_attributes(params[:user])
    flash[:success] = "Profile updated"
    sign_in @user
    redirect_to @user
  elsif @title = "Account"
    render 'account'
  else
    render 'edit'
  end
end
(拆分形式视图)

EDIT.HTML.ERB

<%= form_for @user, :html => { :multipart => true } do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :avatar %><br />
  <%= f.file_field :avatar %>

  <%= f.label :location %>
  <%= f.text_field :location %>

  <%= f.label :website %>
  <%= f.text_field :website %>

  <%= f.label :bio %>
  <%= f.text_area :bio, placeholder: "About yourself in 160 characters or less..." %>

  <%= f.submit "Update Profile", class: "btn btn-medium btn-primary" %>
<% end %>
<%= form_for @user, :html => { :multipart => true } do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :email %>
  <%= f.text_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.label :password_confirmation, "Confirm Password" %>
  <%= f.password_field :password_confirmation %>

  <%= f.submit "Update Account", class: "btn btn-medium btn-primary" %>
<% end %>
{:multipart=>true}do | f |%>

ACCOUNT.HTML.ERB

<%= form_for @user, :html => { :multipart => true } do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :avatar %><br />
  <%= f.file_field :avatar %>

  <%= f.label :location %>
  <%= f.text_field :location %>

  <%= f.label :website %>
  <%= f.text_field :website %>

  <%= f.label :bio %>
  <%= f.text_area :bio, placeholder: "About yourself in 160 characters or less..." %>

  <%= f.submit "Update Profile", class: "btn btn-medium btn-primary" %>
<% end %>
<%= form_for @user, :html => { :multipart => true } do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :email %>
  <%= f.text_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.label :password_confirmation, "Confirm Password" %>
  <%= f.password_field :password_confirmation %>

  <%= f.submit "Update Account", class: "btn btn-medium btn-primary" %>
<% end %>
{:multipart=>true}do | f |%>
编辑和帐户视图中的侧导航栏,因此用户可以访问编辑和帐户表单

<ol class="nav nav-tabs nav-stacked">
  <% @user ||= current_user %>
    <li>
      <a href="<%= edit_user_path(@user) %>">
      Profile
      <i class="icon-chevron-right"></i>
      </a>
    </li>
    <li>
      <a href="<%= account_user_path(@user) %>">
      Account
      <i class="icon-chevron-right"></i>
      </a>
    </li>
</ol>


  • 我发现这是将用户编辑表单拆分为编辑和帐户的最简单方法

    原来我有

    :name, 
    :email, 
    :avatar, 
    :location, 
    :website, 
    :bio,  
    :password (all in one form)
    
    路线(这提供了路线: 账户_用户获取/users/:id/账户(:格式)用户#账户)

    用户\u CONTROLLER.RB

    before_filter :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers, :account]
    before_filter :correct_user,   only: [:edit, :update, :account]
    
    
    def edit
      @user = User.find(params[:id])
    end
    
    def account
      @title = "Account"
      @user = User.find(params[:id])
    end
    
    def update
      if @user.update_attributes(params[:user])
        flash[:success] = "Profile updated"
        sign_in @user
        redirect_to @user
      elsif @title = "Account"
        render 'account'
      else
        render 'edit'
      end
    end
    
    (拆分形式视图)

    EDIT.HTML.ERB

    <%= form_for @user, :html => { :multipart => true } do |f| %>
      <%= render 'shared/error_messages', object: f.object %>
    
      <%= f.label :name %>
      <%= f.text_field :name %>
    
      <%= f.label :avatar %><br />
      <%= f.file_field :avatar %>
    
      <%= f.label :location %>
      <%= f.text_field :location %>
    
      <%= f.label :website %>
      <%= f.text_field :website %>
    
      <%= f.label :bio %>
      <%= f.text_area :bio, placeholder: "About yourself in 160 characters or less..." %>
    
      <%= f.submit "Update Profile", class: "btn btn-medium btn-primary" %>
    <% end %>
    
    <%= form_for @user, :html => { :multipart => true } do |f| %>
      <%= render 'shared/error_messages', object: f.object %>
    
      <%= f.label :email %>
      <%= f.text_field :email %>
    
      <%= f.label :password %>
      <%= f.password_field :password %>
    
      <%= f.label :password_confirmation, "Confirm Password" %>
      <%= f.password_field :password_confirmation %>
    
      <%= f.submit "Update Account", class: "btn btn-medium btn-primary" %>
    <% end %>
    
    {:multipart=>true}do | f |%>
    
    ACCOUNT.HTML.ERB

    <%= form_for @user, :html => { :multipart => true } do |f| %>
      <%= render 'shared/error_messages', object: f.object %>
    
      <%= f.label :name %>
      <%= f.text_field :name %>
    
      <%= f.label :avatar %><br />
      <%= f.file_field :avatar %>
    
      <%= f.label :location %>
      <%= f.text_field :location %>
    
      <%= f.label :website %>
      <%= f.text_field :website %>
    
      <%= f.label :bio %>
      <%= f.text_area :bio, placeholder: "About yourself in 160 characters or less..." %>
    
      <%= f.submit "Update Profile", class: "btn btn-medium btn-primary" %>
    <% end %>
    
    <%= form_for @user, :html => { :multipart => true } do |f| %>
      <%= render 'shared/error_messages', object: f.object %>
    
      <%= f.label :email %>
      <%= f.text_field :email %>
    
      <%= f.label :password %>
      <%= f.password_field :password %>
    
      <%= f.label :password_confirmation, "Confirm Password" %>
      <%= f.password_field :password_confirmation %>
    
      <%= f.submit "Update Account", class: "btn btn-medium btn-primary" %>
    <% end %>
    
    {:multipart=>true}do | f |%>
    
    编辑和帐户视图中的侧导航栏,因此用户可以访问编辑和帐户表单

    <ol class="nav nav-tabs nav-stacked">
      <% @user ||= current_user %>
        <li>
          <a href="<%= edit_user_path(@user) %>">
          Profile
          <i class="icon-chevron-right"></i>
          </a>
        </li>
        <li>
          <a href="<%= account_user_path(@user) %>">
          Account
          <i class="icon-chevron-right"></i>
          </a>
        </li>
    </ol>