【发布时间】:2013-05-31 04:28:07
【问题描述】:
我可能在做一些愚蠢的事情,但是......
app/model/user.rb:
class User < ActiveRecord::Base
has_one :totem
config/routes.rb:
resources :users do
resource :totem
end
app/controllers/totems_controller.rb:
class TotemsController < ApplicationController
before_filter do
@user = User.find(params[:user_id])
end
def new
@totem = @user.build_totem
end
end
app/views/totems/new.html.erb:
<%= form_for [@user, @totem] do |f| %>
<% end %>
然后,当我导航到 /users/123/totem/new 时,我收到错误:
ActionView::Template::Error (undefined method `user_totems_path' for #<#<Class:0x007f9d3c843b00>:0x007f9d3bb6dd68>):
但是因为我在 routes.rb 中使用 resource :totem 而不是 resources :totems,所以它应该使用的路径助手是 user_totem_path。为什么不尝试使用正确的路径助手?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3