0

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.

James Klein
  • 612
  • 4
  • 15
  • 1
    Weird! did yu try restarting the server..? – aBadAssCowboy Jan 18 '14 at 02:30
  • Rename your model to `WatchedWatcher`(no underscore). – usha Jan 18 '14 at 03:12
  • Have you tried removing your logic from the `create` action & replacing with `Rails.logger.info("testing")`? This will allow you to see if the action is actually being found, but your system just gets caught with errors – Richard Peck Jan 18 '14 at 10:29
  • I tried restarting sveral time, no luck. I renamed the model and now I am getting this error: 'Template is missing Missing template watched_watchers/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/james/Dropbox/GitHubRepo/csi-follower/app/views" * "/Users/...'. It looks as if it is looking for a view but I am trying to create a record and reload the same page @Vimsha . No change with Rails.logger.info("testing") with this new error. – James Klein Jan 18 '14 at 18:57
  • That worked! Once I fixed the model name I just needed to have a redirect back to the same page. Thanks a lot everyone! – James Klein Jan 18 '14 at 19:07

1 Answers1

0

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.

James Klein
  • 612
  • 4
  • 15