无法为WatchedWatchersController找到“创建”操作

时间:2014-01-18 02:02:19

标签: ruby-on-rails controller link-to

我为此搜索了高低,其他解决方案似乎没有帮助。 错误:

The action 'create' could not be found for WatchedWatchersController

点击视图中使用此代码创建的链接后,我得到了这个:

<%= link_to 'Watchlist', {  :controller => "watched_watchers", 
                                    :action => "create", 
                                    :watcher_id => current_user.id, 
                                    :watched_id => user.id}, 
                                    :method => "post" %>

我这个班的模型是:

class Watched_Watcher < ActiveRecord::Base
  attr_accessible :watched_id, :watcher_id

  validates :watched_id, :watcher_id, presence: true
end

我的控制器是:

class WatchedWatchersController < ApplicationController
  def new
  end

  def create
    @ww = Watched_Watcher.new
    @ww.watcher_id = params[:watcher_id]
    @ww.watched_id = params[:watched_id]
    @ww.save
  end

  def update
  end

  def edit
  end

  def destroy
  end

  def index
  end

  def show
  end
end

我已将路由设置为RESTful资源:

  resources :watched_watchers

rake路线显示:

POST   /watched_watchers(.:format)          watched_watchers#create

所以我很难过,任何帮助都表示赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:0)

Vimsha的评论解决了这个问题 “将您的模型重命名为WatchedWatcher(无下划线)”。然后,一旦我修复了模型名称,我就需要重定向到同一页面。