全轨道新手,请耐心听我说。我已经卡住了很长一段时间,试图弄清楚如何使一个页面,允许登录的用户改变,通过文本字段,用户模型的某些属性。例如,我的用户模型有许多我想通过页面直接修改的"度量"属性。我的用户模型是在设计上运行的——我不确定直接修改用户模型是否正确。
这是我的控制器。我将它设置为查找第二个用户,因为我只是想测试一下它是否有效。
class MeasurementsController < ApplicationController
def index
@person = User.find(2)
end
end
这是我的index.html.erb:
<%= form_for @person do |f| %>
<%= f.label :style %>:
<%= f.text_field :style %><br />
<%= f.submit "Update"%>
<% end %>
但是,它吐出这个错误:
NoMethodError in Measurements#index
undefined method `user_path'
任何帮助都将非常感激。提前谢谢你。我真的迷路了。
编辑:这是我的路由。rb:
Contourfw::Application.routes.draw do
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users
root :to => 'contourfw#landingpage'
match "measurements" => "measurements#index"
match "styles" => "styles#index"
end
看起来你需要在config/routes.rb中添加一个资源路由:
resources :users
默认情况下,它将假定一个名为users_controller.rb的控制器。如果你想让它使用上面的控制器,修改为:
resources :users, :controller => "measurements"