rails acts_as_state_machine no method error

456 Views Asked by At

I am getting this error while trying to follow a tutorial over here

http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video.html

I have the table called videos with field needed as tutorial says, but when trying to get the index in browser I have this ugly error. How can this be solved? Thanks.

NoMethodError in VideosController#index

undefined method `acts_as_state_machine' for #<Class:0xb5a5f5b8>

Application Trace | Framework Trace | Full Trace

app/models/video.rb:9
app/controllers/videos_controller.rb:3:in `index'

videos controller

class VideosController < ApplicationController
  def index
    @videos = Video.find :all
  end

  def new
    @video = Video.new
  end

  def create
    @video = Video.new(params[:video])
    if @video.save
      @video.convert
      flash[:notice] = 'Video has been uploaded'
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end

  def show
    @video = Video.find(params[:id])
  end
end

video.rb

class Video < ActiveRecord::Base
   # Paperclip
  # http://www.thoughtbot.com/projects/paperclip
  has_attached_file :source

  validates_attachment_presence :source
  validates_attachment_content_type :source, :content_type => 'video/quicktime'

  acts_as_state_machine :initial => :pending
  state :pending
  state :converting
  state :converted, :enter => :set_new_filename
  state :error

  event :convert do
    transitions :from => :pending, :to => :converting
  end

  event :converted do
    transitions :from => :converting, :to => :converted
  end

  event :failed do
    transitions :from => :converting, :to => :error
  end
1

There are 1 best solutions below

0
On

I had the same problem.

I solved it by copy directory acts_as_state_machine from another working project\plugins

Hope this help.

Dat