ruby on rails - Using form_for and form_tag whilst still passing params -



ruby on rails - Using form_for and form_tag whilst still passing params -

this easy 1 looking clarification can understand happening. using stripe create payment , have set form using form_tag

<%= form_tag donations_path, id: 'payment-form' %> <%= text_field_tag :email, nil, placeholder: "email address", class: 'form-control', :data => {:stripe => 'email' } %> <%= text_field_tag :card_number, nil, name: nil, :placeholder => "card number", class: 'form-control', :data => {:stripe => 'number' } %> <!--more fields here--> <% end %>

now when submitting form via controller

class donationscontroller < applicationcontroller def new end def create @amount = params[:donation_amount].to_i # create client object client = stripe::customer.create( :email => params[:email], :card => params[:stripetoken] ) charge = stripe::charge.create( :customer => customer.id, :amount => @amount, :description => 'rails stripe customer', :currency => 'usd' ) rescue stripe::carderror => e flash[:error] = e.message redirect_to donations_path end private def donation_params params.require(:donation).permit(:id, :campaign_id, :name, :email, :message, :donation_amount) end end

the params passed are

authenticity_token randomtokenhere email richlewis14@gmail.com stripetoken tok_104hxi4dl3s6wpxhx5btcxmw utf8 ✓

if alter form form_for , utilize next form, stripetoken no longer generated

authenticity_token randomtokenhere email richlewis14@gmail.com utf8 ✓

and wondering how can work

new form

<%= form_for @donation, id: 'payment-form' |f| %> <%= f.text_field :email, placeholder: "email address", class: 'form-control', :data => {:stripe => 'email' } %> <%= text_field_tag :card_number, nil, name: nil, :placeholder => "card number", class: 'form-control', :data => {:stripe => 'number' } %> <!--more fields here--> <% end %>

new controller

class donationscontroller < applicationcontroller def new @donation = donation.new end def create @dontation = donation.new(donation_params) @amount = params[:donation][:donation_amount].to_i # create client object client = stripe::customer.create( :email => params[:donation][:email], :card => params[:stripetoken] ) charge = stripe::charge.create( :customer => customer.id, :amount => @amount, :description => 'rails stripe customer', :currency => 'usd' ) rescue stripe::carderror => e flash[:error] = e.message redirect_to donations_path end private def donation_params params.require(:donation).permit(:id, :campaign_id, :name, :email, :message, :donation_amount) end end

im missing simple im sure if can point out much appreciated

thanks

although did not mention that, guess stripetoken added javascript relies on finding form#payment-form, right?

so error might be, sec form not right id.

when using form_for have pass html attributes this:

<%= form_for @donation, html: { id: 'payment-form' } |f| %> ... <% end %>

ps: there typo in sec controllers 'create' method (@dontation instead of @donation)

ruby-on-rails ruby ruby-on-rails-4 stripe-payments form-for

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -