【问题标题】:Rails 3 - Setting up an Account Controller w ViewsRails 3 - 使用视图设置帐户控制器
【发布时间】:2010-11-06 22:06:55
【问题描述】:

我有一个带有 Devise 的 Rails 3 应用程序...

我想创建一个帐户控制器,允许用户更新他们的帐户,例如个人资料、帐户、通知、密码等...

这是我到目前为止所做的。

我生成了一个帐户控制器,它给了我以下信息:

路线:

  get "account/profile"
  get "account/password"
  get "account/notices"

观看次数 现在存在给定上面的名称与 /views/account/...

我的控制器

class AccountController < ApplicationController

  before_filter :authenticate_user!

  def profile
    @user = User.find(current_user.id)
  end

  def password
  end

  def notices
  end

  def privacy
  end

  def disable
  end

end

查看帐户资料:

<% form_for @user, :html => { :multipart => true} do |f| %>

问题是这样的形式:

<form accept-charset="UTF-8" action="/users/13" class="edit_user" enctype="multipart/form-data" id="edit_user_13" method="post">

我希望它像 /account/profile/update 一样,这是表单应该发布的位置?

这是我第一次做这样的事情。我走在正确的轨道上吗?如何添加 /account/profile/update 部分?在路由中添加一些东西并更改表单标签???有没有更清洁的方法可以在路线中做到这一点?

谢谢

【问题讨论】:

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


    【解决方案1】:

    您应该尽可能坚持使用 RESTful 路由。与/profile/123/update 之类的 URL 不同,RESTful 替代方案是使用 HTTP 的/profile/123 PUT

    阅读本文以了解有关 Rails 3 中 RESTful 路由的更多信息:http://edgeguides.rubyonrails.org/routing.html

    另外,看看在您的路线中使用嵌套资源来获取配置文件、通知等(rails 文档中的第 2.7 节):

    resources :accounts do
      resources :profiles, :notices
    end
    

    例如,使用嵌套资源进行编辑会给你这样的路线:

    /accounts/123/notices/3/edit
    

    【讨论】:

      猜你喜欢
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 2017-10-02
      相关资源
      最近更新 更多