RailsCasts Pro episodes are now free!

Learn more or hide this

Nick Treffiletti's Profile

GitHub User: Tref

Site: http://www.NickTreffiletti.com

Comments by Nick Treffiletti

Avatar

Does anyone have any examples of using stripe in a nested form. For example I have a nested form that contains an affiliate which has_one subscription. This same affiliate also has a captcha. The problem is that that if i do something like

ruby
if @affiliate.subscription.save_with_payment && @affiliate.save_with_captcha

and there are errors with my affiliate model but not my subscription model, then the subscription gets saved without an affiliate_id, a customer is created by stripe and the same form re-renders populated with the stripe_token and the newly created subscription_id. Once the form is resubmitted and Affiliate.new(params[:affiliate] ) is called in the create action it is raising an error like Couldn't find Subscription with ID=31 for Affiliate with ID= since there is no affiliate_id in the subscription row in the DB. It would really be nice to see an example of this inside a nested form. Help!

Avatar

Was noticing that this was not doing anything to standardize the capitalizations so therefore tagname and Tagname are two different things in this implementation, in order to fix this I simply used a before_save to titleize the names with this:

ruby
before_save :titleize

def titleize
  self.name = self.name.titleize
end

Pretty simple but assigning of the name threw me for a loop for a minute. Great cast!