Rails 3 - 设置帐户控制器w视图

时间:2010-11-06 22:06:55

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

我有一个带有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部分?在路线中添加一些东西并更改表格标签???在路线上有更清洁的方法吗?

谢谢

1 个答案:

答案 0 :(得分:2)

你应该尽可能坚持使用RESTful路线。使用HTTP /profile/123/update

,RESTful替代方案不是/profile/123之类的网址PUT

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

另外,请查看路由中使用嵌套资源的配置文件,通知等(rails doc中的第2.7节):

resources :accounts do
  resources :profiles, :notices
end

例如,使用嵌套资源进行编辑将为您提供如下路径:

/accounts/123/notices/3/edit