"``transition :available_to``" doesn't set acting_user
Reported by Tomoaki Hayasaka | January 15th, 2011 @ 06:58 AM | in Hobo 1.0X
(Hobo 1.0.2, ruby 1.8.7) and (Hobo 1.3.0pre25, ruby 1.9.2p0)
When Hobo evaluates ":available_to
" expressions, it
doesn't set model.acting_user. Because of this, "Tutorial 23 -
Using Hobo Lifecycles for Workflow" example on page 273 of the
"Rapid Rails with Hobo" book fails with "NoMethodError:
undefined method `sign_up?' for nil:NilClass
".
# app/models/recipe.rb:
class Recipe < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
title :string
timestamps
end
def log_backtrace
logger.warn("@@ acting_user (shouldn't be nil) = #{acting_user.inspect}\n")
logger.warn(" #{caller[0, 15].join("\n ")}\n")
end
lifecycle :state_field => :lifecycle_state do
state :not_published, :default => true
state :published
transition :publish, { :not_published => :published }, :available_to => "log_backtrace; ::User"
# transition :publish, { :not_published => :published }, :available_to => "acting_user if acting_user.signed_up?"
end
def create_permitted?; true; end
def update_permitted?; true; end
def destroy_permitted?; true; end
def view_permitted?(field); true; end
end
# app/controllers/recipes_controller.rb:
class RecipesController < ApplicationController
hobo_model_controller
auto_actions :all
end
# app/views/recipes/index.dryml:
<index-page>
<collection: replace>
<div>
<table-plus fields="id, lifecycle_state, title">
<controls:>
<transition-buttons/>
</controls:>
</table-plus>
</div>
</collection:>
</index-page>
# and create a record
>> Recipe.create!(:title => "The Golden Recipe")
=> #<Recipe id: 1, title: "The Golden Recipe", created_at: "2011-01-15 05:50:59", updated_at: "2011-01-15 05:50:59", lifecycle_state: "not_published", key_timestamp: nil>
>> Recipe.count
=> 1
Visiting /recipes, you'll get these traces:
Started GET "/recipes" for 127.0.0.1 at 2011-01-15 15:31:59 +0900
SQL (0.3ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (0.2ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Processing by RecipesController#index as HTML
User Load (0.5ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
Recipe Load (0.2ms) SELECT "recipes".* FROM "recipes" LIMIT 30 OFFSET 0
User Load (1.0ms) SELECT "users".* FROM "users" LIMIT 30
@@ acting_user (shouldn't be nil) = #<User id: 1, crypted_password: "6c01a8cb611aa67b6ff041fbbfa1a8a7476ec14d", salt: "79ab038b611910fc6c6c5b331aef7f3d1346d001", remember_token: nil, remember_token_expires_at: nil, name: "Tomoaki Hayasaka", email_address: "hayasaka@example.com", administrator: true, created_at: "2011-01-15 06:18:35", updated_at: "2011-01-15 06:18:35", state: "active", key_timestamp: nil>
(eval):1:in `__top_level_eval__'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:5:in `instance_eval'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:5:in `__top_level_eval__'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:61:in `run_hook'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:40:in `publishable_by'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:53:in `acting_user_is?'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:15:in `available_to_acting_user?'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:103:in `can_run?'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:147:in `block (2 levels) in available_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:147:in `select'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:147:in `block in available_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/permissions.rb:168:in `with_acting_user'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:146:in `available_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:152:in `publishable_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml:55:in `block (2 levels) in transition_buttons'
@@ acting_user (shouldn't be nil) = nil
(eval):1:in `__top_level_eval__'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:5:in `instance_eval'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:5:in `__top_level_eval__'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:61:in `run_hook'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/actions.rb:40:in `publishable_by'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:152:in `block in publishable_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:152:in `select'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/model/lifecycles/lifecycle.rb:152:in `publishable_transitions_for'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml:55:in `block (2 levels) in transition_buttons'
/var/lib/gems/1.9.1/gems/dryml-1.3.0.pre25/lib/dryml/template_environment.rb:247:in `block in new_context'
/var/lib/gems/1.9.1/gems/actionpack-3.0.3/lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
/var/lib/gems/1.9.1/gems/dryml-1.3.0.pre25/lib/dryml/template_environment.rb:247:in `new_context'
/var/lib/gems/1.9.1/gems/hobo-1.3.0.pre25/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml:54:in `block in transition_buttons'
/var/lib/gems/1.9.1/gems/dryml-1.3.0.pre25/lib/dryml/template_environment.rb:327:in `block in _tag_context'
/var/lib/gems/1.9.1/gems/dryml-1.3.0.pre25/lib/dryml/template_environment.rb:247:in `block in new_context'
Rendered recipes/index.dryml (347.3ms)
Completed 200 OK in 356ms (Views: 347.7ms | ActiveRecord: 2.2ms)
Note that the ":available_to
" expression is
evaluated twice for one record, and on second time
acting_user
is nil.
Comments and changes to this ticket
-
Domizio Demichelis March 27th, 2011 @ 08:14 PM
- State changed from new to open
- Milestone set to Hobo 1.0X
- Assigned user set to Bryan Larsen
- Milestone order changed from 197937 to 0
Since it is affecting also the 1.0.x, the fix for 1.3 will be ported next.
-
Domizio Demichelis March 31st, 2011 @ 12:53 AM
- State changed from open to resolved
(from [3d19d5ce72db981083e241e5a271af2319b73703]) fix for transition :available_to => not setting the acting_user [#900 state:resolved] [#933] https://github.com/tablatom/hobo/commit/3d19d5ce72db981083e241e5a27...
-
Domizio Demichelis March 31st, 2011 @ 12:56 AM
- State changed from resolved to open
Sorry, Bryan,
The commits sets the state but it is still open for 1.0.x.
You could probably apply the same to 1.0.x. -
johndavidd September 14th, 2022 @ 05:43 AM
I don't look familiar feeling a bit confusing? Can you elaborate on phrazle on weaver game?
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
People watching this ticket
Tags
Referenced by
- 933 acting_user not valid in :available_to parameter of 'create' transition (from [3d19d5ce72db981083e241e5a271af2319b73703]) fix for...
- 900 "``transition :available_to``" doesn't set acting_user (from [3d19d5ce72db981083e241e5a271af2319b73703]) fix for...
- 933 acting_user not valid in :available_to parameter of 'create' transition see #900