I'm using stripe.js, got this:
<%= form_tag charges_path, id: 'payment-form' do %>
<span class="payment-errors"></span>
<div class="form-group">
<label>
<span>Your email</span>
<input type="text" size="20" data-stripe="email">
</label>
</div>
<div class="form-group">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number">
</label>
</div>
<div class="form-group">
<label>
<span>Expiration (MM/YY)</span>
<input type="text" size="2" data-stripe="exp_month">
</label>
<span> / </span>
<input type="text" size="2" data-stripe="exp_year">
</div>
<div class="form-group">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc">
</label>
</div>
<input type="submit" class="submit" value="Submit Payment">
<% end %>
How do I add new fields to submit to stripe? such as name, address, etc. I think it has something to do with changing data-stripe but I couldn't find a "list" of the values that stripe accepts. Any ideas?
As per Stripe docs Updatable Stripe objects (Account, Charge, Customer, Refund, Subscription, and Transfer) have a metadata parameter. You can use this parameter to attach key-value data to these Stripe objects.
You can check HERE for the list of attributes of the Charge object.
In your question you refer to some attributes which can be better related to the user (Customer) rather than the Charge itself.
You can check HERE for the list of attributes of the Customer object.
You can use something like the following in your controller:
customer = Stripe::Customer.create(
:email => params[:email],
:source => params[:stripeToken],
:metadata => {
:address => params[:address],
:city => params[:city],
:region => params[:region],
:country => params[:country]
}
)
Related
Is it possible to have the checkbox labels on the left like the others, and the checkbox on the right like the other inputs with a horizontal form?
My current setup
It looks pretty awful.
EDIT:
<%= simple_form_for :apartment, :html => {:multipart => true, :class => 'form-horizontal'}, wrapper: :horizontal_form do |f| %>
<%= f.input :pets, as: :boolean, label: 'Husdyr tilladt' %>
<% end %>
which generates the following html in the view:
<div class="form-group boolean optional apartment_pets">
<div class="checkbox"><input value="0" type="hidden" name="apartment[pets]">
<label class="boolean optional" for="apartment_pets"><input class="boolean optional" type="checkbox" value="1" name="apartment[pets]" id="apartment_pets">
Husdyr tilladt
</label>
</div>
</div>
You can add pull-right to the class of your checkbox element like so:
<input name="uh" id="uhhuh" type="checkbox" class="pull-right" />
Updated answer with user provided code:
<div class="form-group boolean optional apartment_pets">
<div class="checkbox"><input value="0" type="hidden" name="apartment[pets]">
<label class="boolean optional" for="apartment_pets">Husdyr tilladt</label>
<input class="boolean optional" type="checkbox" value="1" name="apartment[pets]" id="apartment_pets" class="pull-right">
</div>
</div>
I never used simple_form but from browsing the documentation, it looks like you should use a combination of :label => false and :inline_label => true to position your label.
So I got stripe up and running, however I have 3 different payment plans.
I'd like to capture what plan they clicked on, and use that to connect them to their right plan id.
This is what my form looks like:
<%= form_tag charges_path, id: "payment-form" do %>
<span class="payment-errors"></span>
<div class="form-row">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number" maxlength="20" />
</label>
</div>
<div class="form-row">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc" maxlength="4"/>
</label>
</div>
<div class="form-row">
<label>
<span>Expiration (MM/YYYY)</span>
<input type="text" size="2" data-stripe="exp-month" maxlength="2"/>
</label>
<span> / </span>
<input type="text" size="4" data-stripe="exp-year" maxlength="4"/>
</div>
<button type="submit">Submit Payment</button>
<% end %>
I link to them like this:
<%= link_to 'Start Your Free Trial', new_charge_path(:plan_id => 1) %>
and the controller looks like this:
def create
customer = Stripe::Customer.create(
:email => 'exaimple#stripe.com',
:plan => plan_id,
:card => params[:stripeToken]
)
current_user.update_attributes(:stripe_customer_token => customer.id)
redirect_to root_url, notice: 'Successfully subscribed'
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
which results in the error:
undefined local variable or method `plan_id'
I am working on Rails4 with Nested form, accepts_nested_attributes_for i can able to generate the nested form but its giving dynamic array the the form when i inspect the form.
<input type="text" name="event_venue[event_contact_details_attributes][1403763304978][name]" id="event_venue_event_contact_details_attributes_1403763304978_name" class="form-control">
But it should be,
<input type="text" name="event_venue[event_contact_details_attributes][1][name]" id="event_venue_event_contact_details_attributes_1_name" class="form-control">
<div class="formWrapper">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" name="event_venue[event_contact_details_attributes][1403764358820][name]" id="event_venue_event_contact_details_attributes_1403764358820_name" class="form-control">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Phone</label>
<input type="text" name="event_venue[event_contact_details_attributes][1403764358820][telephone]" id="event_venue_event_contact_details_attributes_1403764358820_telephone" class="form-control">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="text" name="event_venue[event_contact_details_attributes][1403764358820][email]" id="event_venue_event_contact_details_attributes_1403764358820_email" class="form-control">
</div>
<div class="clearfix"></div>
<input type="hidden" value="false" name="event_venue[event_contact_details_attributes][1403764358820][_destroy]" id="event_venue_event_contact_details_attributes_1403764358820__destroy"><a onclick="remove_fields(this); return false;" href="#">remove</a>
</div>
</div>
Can you help me out where i am missing the things...!!!
In first nested form set it's coming right,
<div class="formWrapper">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" value="AS" name="event_venue[event_contact_details_attributes][0][name]" id="event_venue_event_contact_details_attributes_0_name" class="form-control">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Phone</label>
<input type="text" value="AS" name="event_venue[event_contact_details_attributes][0][telephone]" id="event_venue_event_contact_details_attributes_0_telephone" class="form-control">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="text" value="AS" name="event_venue[event_contact_details_attributes][0][email]" id="event_venue_event_contact_details_attributes_0_email" class="form-control">
</div>
<div class="clearfix"></div>
<input type="hidden" value="false" name="event_venue[event_contact_details_attributes][0][_destroy]" id="event_venue_event_contact_details_attributes_0__destroy"><a onclick="remove_fields(this); return false;" href="#">remove</a>
</div>
</div>
Event Venue Model,
has_many :event_contact_details, :dependent => :destroy
accepts_nested_attributes_for :event_contact_details, allow_destroy: true
Controller,
def new
#event_venue = EventVenue.new
#event_venue.event_contact_details.build
end
form,
<%= f.fields_for :event_contact_details do |builder| %>
<%= render :partial => 'event_venues/event_contact_detail_fields',
:locals => { :f => builder } %>
<% end %>
<p><%= link_to_add_fields "Add More", f, :event_contact_details %></p>
I am trying to create a form that displays the radio options inline like this:
O Apple O Microsoft O Twitter O Square
Currently I have this line:
<%= f.association :company, as: :radio, label: false %>
But my form looks like this:
O Apple
O Microsoft
O Twitter
O Square
I have tried <div class="form-inline"></div> around that input and also adding
<%= f.association :company, as: :radio, label: false, :item_wrapper_class => 'inline' %>
Do I need to change the input to collection?
with regular rails you can do
<div class="radio">
<label>
<%= radio_button_tag "Product Type", "Retail Product or Service", true %>
Retail Product or Service
</label>
<label>
<%= radio_button_tag "Product Type", "Tax Code", false %>
Tax Code
</label>
<label>
<%= radio_button_tag "Product Type", "Discount Amount", false %>
Discount Amount
</label>
<label>
<%= radio_button_tag "Product Type", "Discount Percent", false %>
Discount Percent
</label>
</div>
You can use this:
<label class="checkbox inline">
<input type="checkbox" id="inlineCheckbox1" value="option1"> 1
</label>
<label class="checkbox inline">
<input type="checkbox" id="inlineCheckbox2" value="option2"> 2
</label>
<label class="checkbox inline">
<input type="checkbox" id="inlineCheckbox3" value="option3"> 3
</label>
Or this one (tag form only):
<form class="form-inline">
<input type="text" class="input-small" placeholder="Email">
<input type="password" class="input-small" placeholder="Password">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</form>
I have my form
<% form_tag users_path, :id => 'registrationForm' do %>
<div class="formElement">
<label for="emailAddress">Email Address</label>
<input name="user[email]" type="text">
</div>
<div class="formElement">
<label for="password">Password</label>
<input id="password" name="user[password]" type="password">
</div>
<div class="formElement">
<label for="passwordConfirmation">Re-Enter Password</label>
<input id="passwordConfirmation" name="user[password_confirmation]" type="password">
</div>
<div class="formElement right">
<input name="commit" value="Create" type="submit">
</div>
<% end %>
and then my controller method to process this which contains
#user = User.new(params[:user])
#user.save do |result|
...
end
This works fine. However, if I add 'first_name' and 'last_name' fields to my database table and add
<div class="formElement">
<label for="firstName">First Name</label>
<input id="firstName" name="user[first_name]" type="text" />
</div>
<div class="formElement">
<label for="lastName">Last Name</label>
<input id="lastName" name="user[last_name]" type="text" />
</div>
to my form, I get
Mysql::Error: Column 'last_name'
cannot be null: INSERT INTO users
(salt, ship_address_id,
created_at, single_access_token,
last_request_at, bill_address_id,
crypted_password,
remember_token_expires_at,
updated_at, perishable_token,
api_key, failed_login_count,
current_login_ip,
openid_identifier,
current_login_at, last_name,
remember_token, persistence_token,
login_count, last_login_ip,
last_login_at, login, email,
first_name)
VALUES('gPa4FNsPHbfxLz1FTZJ8', NULL,
'2010-11-03 18:07:24',
'INl0QTDduoCKSdLLXEqb', '2010-11-03
18:07:24', NULL,
'900d7300768651e4814ca16b1dd39b85e8111c92a63d366c82e3f1d501dc7b85efc060bc2032e55e4405fe33b0883b0ad586fe47e99261b046a34a8b9d785333',
NULL, '2010-11-03 18:07:24',
'r8YSPUfKsmbIIJryvz5C', NULL, 0,
'127.0.0.1', NULL, '2010-11-03
18:07:24', NULL, NULL,
'd4fe33e9c1bde5e2468d74d3dc1de28089f565d7e0d39584690452547be6d3bbf529e9ac118575529f34e377cce315697538c64b19f799e386d6977a8f37912e',
1, NULL, NULL, 'testuser3#test.com',
'testuser3#test.com', NULL)
Here's the parameters the error page says were passed:
{"commit"=>"Create",
"authenticity_token"=>"tFpn+DGMU3VfeaSrc5ckVoVCxfy76Xm0Mqf8Jx8JEFs=",
"user"=>{"password_confirmation"=>"test",
"last_name"=>"User3",
"password"=>"test",
"first_name"=>"Test3",
"email"=>"testuser3#test.com"}}
Any ideas why I get this MySQL error?
Are you using attr_accessible or attr_protected in your User model to guard against mass-assignment exploits?