I have a problem with a lifecycle create, it does not seem to be
finding the item in the belongs to association.
I have the following model class:
class Subscriber < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
email :email_address
timestamps
end
belongs_to :sponsor, :class_name => 'User'
belongs_to :product, :class_name => 'Product',:accessible => true
validates_presence_of :name, :email
validates_uniqueness_of :email,
:message => "Sorry there is already a subscription for that
address. Please try with a different one."
validates_presence_of :product_id, :message => "has not been
selected"
# --- Signup lifecycle --- #
lifecycle do
state :waiting_confirmation, :active, :waiting_unsubscribe
create :subscribe_request, :available_to => :all,
:params => [:name, :email, :sponsor, :products],
:become => :waiting_confirmation
transition :subscription_confirmation_received,
{ :waiting_confirmation => :active }
transition :unsubscribe_request, {:active
=> :waiting_unsubscribe}, :params => [:email]
transition :unsubscribe_request, {:waiting_unsubscribe
=> :waiting_unsubscribe}, :params => [:email]
transition :thankyou_unsubscribe, {:waiting_unsubscribe
=> :destroy}
end
In the controller I have this (with debug puts):
def do_subscribe_request
do_creator_action :subscribe_request do
puts "===========> params " + params.inspect
puts "-----------> subscriber at 1 " + @subscriber.inspect
sub = params[:subscriber]
@subscriber.product_id = sub[:product_id]
puts "-----------> subscriber at 2" + @subscriber.inspect
if valid?
@remote_action = "subscribing"
render :action => "redirect_to_dr"
end
end
end
I added this to force the product_id:
sub = params[:subscriber]
@subscriber.product_id = sub[:product_id]
And clicking on the submit button gives me:
===========> params {"subscriber"=>{"sponsor_id"=>"1", "name"=>"Geoff
Drake", "product_id"=>"1", "email"=>"[email protected]"},
"page_path"=>"subscribers/subscribe_request",
"authenticity_token"=>"8036e5487d226b047c602fa986072597db1a02d3",
"action"=>"do_subscribe_request", "controller"=>"subscribers"}
-----------> subscriber at 1 #<Subscriber id: nil, name: "Geoff
Drake", email: "[email protected]", created_at: nil, updated_at:
nil, sponsor_id: 1, state: "waiting_confirmation", key_timestamp: nil,
product_id: nil>
-----------> subscriber at 2#<Subscriber id: nil, name: "Geoff Drake",
email: "[email protected]", created_at: nil, updated_at: nil,
sponsor_id: 1, state: "waiting_confirmation", key_timestamp: nil,
product_id: 1>
127.0.0.1 - - [28/Apr/2009:15:19:07 CEST] "POST /subscribers/
subscribe_request HTTP/1.1" 200 6419
http://localhost:3005/subscribers/subscribe_request -> /subscribers/
subscribe_request
In the params we have the product_id set.
In the first subscriber i.e. the one created automatically product_id
is nil
In the second I have forced it to be the right value
Yet the original get page is re-rendered with the product selected
correctly, but with the error message "Product has not been selected"
Am I doing something wrong, or is it a bug?
As a second problem, the <select> for product has a first item of "(No
Product)" is there some way to get rid of this?
Cheers
Geoff
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---