我已向注册 Controller 添加了额外的页面来清理用户帐户设置页面。我的问题是,在这些新页面上,虽然我可以更新用户的属性,但这些属性不会显示在 View 中。 我指的是之前保存的属性应该显示在表单上相应的输入中。
我留在 users/edit
页面上的表单属性确实显示了已保存的属性,但新页面没有。
我添加了如下新页面;
路线:
devise_for :users, controllers: { registrations: "users/registrations", sessions: "users/sessions" }
devise_scope :user do
get "/users/account", to: "users/registrations#account"
get "/users/media", to: "users/registrations#media"
get "/users/notifications", to: "users/registrations#notifications"
end
用户/注册 Controller ;
def account
build_resource({})
respond_with self.resource
end
def media
build_resource({})
respond_with self.resource
end
def notifications
build_resource({})
respond_with self.resource
end
每页上的表单:
`<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %`>
为什么保存的属性没有显示在这些新页面上?
最佳答案
好的,我已经弄清楚了。
而不是使用:
build_resource({})
respond_with self.resource
我已添加
def account
@user = current_user
if @user
render :account
else
redirect_to root_url
end
end
........etc.....
现在属性已正确显示。
关于ruby-on-rails - rails 上的 ruby 。设计注册编辑 - 用户属性未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37926919/