Domanda

I've searched high and low for this and the other solutions don't seem to help. The error:

The action 'create' could not be found for WatchedWatchersController

I get this after clicking a link made with this code in a view:

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

My model for this class is:

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

  validates :watched_id, :watcher_id, presence: true
end

And my controller is:

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

I've set up my routes as a RESTful resource:

  resources :watched_watchers

And rake routes reveals:

POST   /watched_watchers(.:format)          watched_watchers#create

So I'm stumped and any help is appreciated. Thanks in advance.

È stato utile?

Soluzione

Vimsha's comment solved it "Rename your model to WatchedWatcher(no underscore)". And then once I fixed the model name I just needed to have a redirect back to the same page.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top