2013-08-07 3 views
3

내 레일 4 앱으로 state_machine gem 사용에 문제가 있습니다. A는 제공된 레일 가이드에 기재된 컬럼 호 상태를 포함하는 모델을 가질 http://gistflow.com/posts/679-state-machine-with-rails-basicsstate_machine gem 레일과 통합 4

있지만 다음과 같이 내 state_machine를 정의 할 때 : 내 IssueConntroller

class IssuesController < ApplicationController 

before_filter :find_issue, except: [:index, :new, :create] 

def index 
    @issues = Issue.all 
end 

def new 
    @issue = Issue.new 
end 

def create 
    @issue = Issue.new(issue_params) 
    respond_to do |format| 
     if @issue.save 
      format.html {redirect_to @issue, :flash => { :success => "Issue succesfully created." } } 
      format.json {head :no_content} 
     else 
      format.html {render action: 'new'} 
      format.json { render json: @issue.errors, status: :unprocessable_entity } 
     end 

    end 
end 

def show 
    @note = Note.new 
    @note.issue_id = @issue.id 
end 

def edit 
end 

def update 
    respond_to do |format| 
     if @issue.update(issue_params) 
     format.html { redirect_to @issue, :flash => { :success => 'Issue was successfully updated.' }} 
     format.json { head :no_content } 
     else 
     format.html { render action: 'edit' } 
     format.json { render json: @issue.errors, status: :unprocessable_entity } 
     end 
    end 
end 

def destroy 
    @issue.destroy 

    flash[:error]= "Issue '#{@issue.title}' Deleted!" 

    redirect_to issues_path 
end 

private 
def issue_params 
    params.require(:issue).permit(:title, :description) 

end 

def find_issue 
    @issue = Issue.find(params[:id]) 
end 

end 
여기

class Issue < ActiveRecord::Base 
validates :title, :description, presence: true 
has_many :notes 

state_machine :initial => :new do 
    state :new, value: 0 
    state :analysed, value: 1 
    state :assigned, value: 2 
    state :inprogress, value: 3 
    state :inreview, value: 4 
    state :validation, value: 5 
    state :resolved, value: 6 
    state :cancelled, value: 7 
    state :closed, value: 8 
    state :rejected, value: 9 
    state :reopened, value: 10 
end 

def next 
    Issue.where("id > ?", self.id).first || Issue.first 
end 

def prev 
    Issue.where("id < ?", self.id).last || Issue.last 
end 
end 

IssuesController # index에서 NoMethodError에 대해 정의되지 않은 메소드`state_machine '에 빠졌습니다. 물론 gemfile에 state_machine 줄을 추가하고 번들 설치 명령을 실행했습니다. 여기

는 아무런 문제가 없습니다 추적

activerecord (4.0.0) lib/active_record/dynamic_matchers.rb:22:in `method_missing' 
app/models/issue.rb:5:in `<class:Issue>' 
app/models/issue.rb:1:in `<top (required)>' 
activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `load' 
activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `block in load_file' 
activesupport (4.0.0) lib/active_support/dependencies.rb:615:in `new_constants_in' 
activesupport (4.0.0) lib/active_support/dependencies.rb:422:in `load_file' 
activesupport (4.0.0) lib/active_support/dependencies.rb:323:in `require_or_load' 
activesupport (4.0.0) lib/active_support/dependencies.rb:462:in `load_missing_constant' 
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing' 
activesupport (4.0.0) lib/active_support/dependencies.rb:494:in `load_missing_constant' 
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing' 
app/controllers/issues_controller.rb:6:in `index' 
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action' 
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action' 
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__901873103026712443__process_action__callbacks' 
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks' 
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action' 
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action' 
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' 
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument' 
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument' 
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action' 
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process' 
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process' 
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch' 
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' 
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call' 
rack (1.5.2) lib/rack/etag.rb:23:in `call' 
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call' 
rack (1.5.2) lib/rack/head.rb:11:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call' 
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context' 
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call' 
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call' 
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call' 
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__77618213725076532__call__callbacks' 
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks' 
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (4.0.0) li/content_length.rb:14:in `call' 
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'b/action_dispatch/middleware/static.rb:64:in `call' 
railties (4.0.0) lib/rails/engine.rb:511:in `call' 
railties (4.0.0) lib/rails/application.rb:97:in `call' 
rack (1.5.2) lib/rack/lock.rb:17:in `call' 
rack (1.5.2) lib/rack/content_length.rb:14:in `call' 
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
/Users/sebmac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 
+0

오류 백 트레이스 및 'IssuesController' 코드는 무엇입니까? –

+0

난 여전히 당신의'issues_controller'가 필요합니다 - 오류 지점. –

+0

이제는 IssueController가 추가되었습니다 :). – SebOnRails

답변

5

입니다) 이

이 문제로 저를 도와 주셔서 감사합니다 ... 레일 응용 프로그램에서로드되지 않습니다 보석처럼 보인다 당신 코드에서 묶음으로 번들을 다시로드하려고 시도 할 때 상태, 모델 및 물론 동일한 이벤트에 대한 값을 사용했기 때문에 또는 ìnteger을 추가하는 것을 잊지 마십시오. 은

입니다. 상태 머신의 정의로
event :add_new do 
     transition new: :analysed 
    end 

: 당신은 여전히 ​​문제를 더 설명하려고있는 경우는 상태 머신

Issue.first.state_name 
    Issue.first.state_events 
    .... 

위한 몇 가지 방법을 호출 할 수 있습니다 rails c 다른

로 전환 폼 상태 :)

+0

바보 같은 문제 ... 고마워. 나는 그것을 어려운 길을 배우고있다. – SebOnRails

+0

나는 서버를 재시동하고 터미널을 재시작했지만 이것으로 도망쳐서 같은 오류가 발생했다. 이유에 대한 다른 아이디어가 있다면 내 문제의 개요는 여기 (http://stackoverflow.com/questions/23400107/state-machine-gem-rails-4-undefined-method-state-machine-for-class0x007f)입니다. 나는이 오류에 빠지 겠어 :) – Morgan