【发布时间】:2013-09-15 18:09:09
【问题描述】:
在我的 Rails 4 代码中,项目是一种资源(我为项目创建了一个数据库迁移,使用 rails generate model item column1:string ...)。我创建了一个控制器 items_controller,其中包含一个方法 htmlupdates。我使用 ajax 调用
url: '/items/htmlupdates'
当我将以下行放入 config/routes.rb 时,我的代码运行良好
get 'items/htmlupdates' => 'items#htmlupdates'
但是当我将以下内容放入 config/routes.rb 时,代码不起作用
resources :items, only: [:new, :htmlupdates, :create]
在终端日志中我收到错误消息:
Started GET "/items/htmlupdates?_12345678..." for 127.0.0.1 at 2013-09-15 10:47:54 -0700
Processing by ItemsController#show as JS
Parameters: {"_"=>12345678...", "id"=>"grades"}
为什么它认为我正在尝试在 items 表中显示 htmlupdate 行? ajax 调用中 url 的正确格式是什么? 谢谢。
【问题讨论】:
-
您的问题中有几个错别字。我不知道您是在此处输入错误还是由于此原因导致的错误。
-
抱歉错别字,错误不是由于错别字造成的。
-
那么你真的用
resources items, only[:new, :htmlupdates, :create]而不是resources :items, :only => [:new, :htmlupdates, :create]吗? -
你的问题很难理解。您能否尝试简化并使用更好的英语。
-
再次抱歉打错字,我使用了资源:items,仅:[:new, :htmlupdates, :create] 但它不起作用。
标签: ruby-on-rails routing ruby-on-rails-4