HAML form wont submit - ruby-on-rails

I'm having trouble with a haml form for stripe. I can't get my submit to function. This is my first time building a from wit haml, any input will help. I'm not even sure if my fields are set up correctly to save into the database.
.container
%section#checkout-form
= form_tag("", method: "POST", id: "payment-form") do
.row
#checkout-form.small-8.columns
.row
#name-form.small-12.columns
.row
.small-6.columns
= label_tag :frist_name, "First Name"
= text_field_tag :name => "First Name", :placeholder => "John", :type => "text"
.small-6.columns
= label_tag :Last_Name, "Last Name"
= text_field_tag :name => "Last Name", :placeholder => "Smith", :type => "text"
.row
.small-12.columns
= label_tag :Email, "Email"
= text_field_tag :name => "Email", :placeholder => "test#test.com", :type => "text"
#address-info.small-12.columns
.row
.small-12.columns
= label_tag :Address1, "Address 1"
= text_field_tag :name => "Address1", :placeholder => "123 Street", :type => "text"
.row
.small-12.columns
= label_tag :Address2, "Address 2"
= text_field_tag :name => "Address2", :placeholder => "Apartment/Suite", :type => "text"
.row
.small-6.columns
= label_tag :City, "City"
= text_field_tag :name => "City", :placeholder => "test", :type => "text"
.small-6.columns
= label_tag :State, "State"
= text_field_tag :name => "State", :placeholder => "test", :type => "text"
.row
.small-6.columns
= label_tag :ZIP, "ZIP"
= text_field_tag :name => "ZIP", :placeholder => "64804", :type => "text"
.small-6.columns
= label_tag :Country, 'Country'
= text_field_tag :name => "Country", :placeholder => "USA", :type => "text"
#billing-info.small-12.columns
.row
.small-6.columns
= label_tag :Credit_Card_Number, "Credit Card Number"
= text_field_tag :name => "Credit Card Number", :placeholder => "1234 5678 9055 5555", :type => "text"
.small-3.columns
= label_tag :Month, "Month"
= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: 'minilabel', "data-stripe" => 'exp-month'}
.small-3.columns
= label_tag :Year, "Year"
= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => 'exp-year'}
.row
.small-6.columns
= label_tag :Security_Code, 'Security Code'
= text_field_tag :name => "Security Code", :placeholder => "123", :type => "text"
.small-6.columns
= label_tag :Billing_ZIP, 'Billing ZIP'
= text_field_tag :name => "Billing ZIP", :placeholder => "64804", :type => "text"
/ Form Side
#checkout-info.small-4.columns
/ Info Side
%img#cards-image{:alt => "", :src => image_path("cards.svg")}/
.hr-with-margin
.reward
%h4 $25 Per Month
%h5 21 people
%p text
%a.button.button-green{:href => "#"} Pledge
/ row
.row.pad-top
.small-12.columns
%submit.button.button-green{type: "submit"} Submit Payment

If you are using form_tag for your form, you need to use a submit_tag for your Submit button. It would look like this:
= submit_tag "Submit", :class=> "button button-green"
And make sure that the submit_tag is nested inside of the form_tag.
Also, you are doing the following with your form tag:
= form_tag("", method: "POST", id: "payment-form") do
But you aren't specifying the route that the form is being submitted to. That first parameter is for specifying the route. So you could do something like this:
= form_tag('/users, method: 'POST', id: 'payment-form') do
if you wanted to post to the '/users' route

Related

Rails form submitting without some params

my form is submitting without params in "Customer Information" and "Shipping Information". The form is rendered in a modal and looks like this
#formShipping.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "productShippingLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog
.modal-content
.modal-header
%button.close{"data-dismiss" => "modal", :type => "button"}
%span{"aria-hidden" => "true"} ×
%span.sr-only Close
%h4#myModalLabel.modal-title Payment Form
.modal-body
/ Button trigger modal
.hide-info
.panel.panel-default
.panel-heading Customer Information
.panel-body
.col-md-3
.col-md-6
%label{:for => "email"} Email Address
%input.form-control{:type => "text"}/
%label{:for => "name"} Name
%input.form-control{:type => "text"}/
%label{:for => "password"} Password
%input.form-control{:type => "text"}/
%label{:for => "password-confirmation"} Password confirmation
%input.form-control{:type => "text"}/
.col-md-3
.panel.panel-default
.panel-heading Shipping Address
.panel-body
.col-md-6
%label{:for => "name"} Name
%input.form-control{:type => "text"}/
%label{:for => "city"} City
%input.form-control{:type => "text"}/
%label{:for => "zipcode"} Zipcode
%input.form-control{:type => "text"}/
.col-md-6
%label{:for => "address"} Address
%input.form-control{:type => "text"}/
%label{:for => "state"} State
%input.form-control{:type => "text"}/
%label{:for => "country"} Country
%input.form-control{:type => "text"}/
.panel.panel-default
.panel-heading
%h3.panel-title Card information
.panel-body
.row
.col-md-6
%label{:for => "name"} Card Number
%input.form-control{:type => "text", "data-stripe" => "number"}/
.col-md-3
%label{:for => "name"} CVC
%input.form-control{:placeholder => "Ex. 331", :type => "text", "data-stripe" => "cvc"}/
.col-md-3
= label_tag :card_month, "Expiration"
= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", "data-stripe" => "exp-month"}
= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => "exp-year"}
.text-center
%h2.total-amount
Total:
$0.00
%input{:name => "terms", :type => "CHECKBOX"}>/
Agree to terms?
%br/
%br
%span.payment-errors
%input{:name => "store_front", :type => "hidden", :value => #store_front.id}/
.text-center
%button.btn.btn-primary{:type => "submit"} Pay Now!
.modal-footer
%button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close
My stripe params come through just fine. But this is the result of checking my submitted params:
>> params
=> {"utf8"=>"✓", "authenticity_token"=>"xkgz3HdfwqS0/AfKpQteT1FaJE/LMhMneUKETCug47qhlw=", "order_products"=>[{"product_id"=>"37", "quanity"=>"0"}, {"product_id"=>"38", "quanity"=>"1"}], "switchName1"=>"on", "custom-amount"=>"", "store_front"=>"34", "stripeToken"=>"token", "action"=>"create", "controller"=>"orders"}
Does anyone know why my inputs aren't submitting?
You've forgotten the name attribute for each one of your input elements.
Change:
%input.form-control{:type => "text"}/
to:
%input.form-control{:type => "text", :name =>"email"}/
and set the correct value for each one of your elements.
You have specified you field for lable but not your input so add that
%label{:for => "email"} Email Address
%input.form-control{:email, :type => "text"}/

Simple_Form: Make two forms work with eachother (dropdown and search)

I have two forms, one containing a dropdown where the user can choose how a list is beeing sorted, the other one containing a searchfield, where the user can search through that list. Now if a user searches for "test" and ten results show up, I want the user to be able to choose from the dropdown, how the results are beeing sorted. Accordingly if he sorts the whole list, I want himto be able to search through the list, with the results showing up in the sorted way he choose before. Due to code restrictions I have to keep those two inputs in different forms.
Here is the sort-dropdown:
= simple_form_for path, :method => "get", html: {id: "sortform"} do |f|
= f.input :sort, :collection => [t(:'videos.date'), t(:'videos.title'), t(:'videos.length')], :label => false, :required => false, :selected => params[:sort], input_html: {class: "control", :id => "sort_dropdown", :name => :sort}, :include_blank => t(:'videos.sort')
And here is the search:
= simple_form_for path, :method => 'get', :label => t(:'videos.search'), html: {id: "search-form"} do |f|
= f.input :q, { input_html: { class: 'form-control searchbar', :name => :q, id: "search", :value => params[:q]}, :placeholder => t(:'videos.search'), :required => false, :label => false}
Is it possible to keep the two inputs seperate or would it be way easier to use just one form?
You can use separate forms if you need to, just store the other parameter in a hidden field in each of the forms.
= simple_form_for path, :method => "get", html: {id: "sortform"} do |f|
= f.input :sort, :collection => [t(:'videos.date'), t(:'videos.title'), t(:'videos.length')], :label => false, :required => false, :selected => params[:sort], input_html: {class: "control", :id => "sort_dropdown", :name => :sort}, :include_blank => t(:'videos.sort')
= f.input :q, as: :hidden, input_html: { :name => :q, :value => params[:q] }
= simple_form_for path, :method => 'get', :label => t(:'videos.search'), html: {id: "search-form"} do |f|
= f.input :q, { input_html: { class: 'form-control searchbar', :name => :q, id: "search", :value => params[:q]}, :placeholder => t(:'videos.search'), :required => false, :label => false}
= f.input :sort, as: :hidden, collection: [t(:'videos.date'), t(:'videos.title'), t(:'videos.length')], :selected => params[:sort], input_html: {class: "control", :id => "sort_dropdown", :name => :sort}, :include_blank => t(:'videos.sort')

Devise multiple sign up pages Rails 4

I want to be able to create different sign up pages for each event in my web app.
I'm using Devise, Cancan and Rolify.
Below is my signup form at the moment:
.container
%h2
Sign up
.tab-content
.tab-pane.active{:id => "signup"}
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-signin'}) do |f|
= f.error_notification
= f.input :email, :required => true, :autofocus => true, input_html: { class: "form-control"}, :placeholder => "Email"
- if f.object.password_required?
= f.input :password, :required => true, input_html: { class: "form-control"}, :placeholder => "Password"
= f.input :password_confirmation, :required => true, input_html: { class: "form-control"}, :placeholder => "Password Confirm"
= f.input :first_name, :required => true, :autofocus => true, input_html: { class: "form-control"}, :placeholder => "First name"
= f.input :last_name, :required => true, :autofocus => true, input_html: { class: "form-control"}, :placeholder => "Last name"
= f.button :submit, "Sign up", :class => "btn btn-lg btn-primary btn-block"
= render "devise/shared/links"
Is there a way we can add in fields from events table so those fields are populated with different urls so each one of them have dedicated signup page for visitors?

Rails select tag in form doesn't populate with value in the edit view

I have the typical rails _form generated by scaffold for a member model. For the param :state I am using a select tag:
<%= f.select :state, options_for_select(us_states), { :include_blank=>true, :prompt => 'State' }, { :class => 'form-control' } %>
Using a helper method (us states):
def us_states
[
['AK', 'AK'],
['AL', 'AL'], #etc
And for the param "member_since" I am using the select_year helper:
<%= select_year(0, {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>
Now both of these selects work to create a new record, but neither field is pre-filled in the edit record view. Any thoughts?
<%= f.select :state, us_states, { :include_blank=>true, :prompt => 'State' }, { :class => 'form-control' } %>
and
<%= select_year(f.object.member_since, {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>
UPDATE:
Since member_since is a string, you will need to convert it to date:
<%= select_year(Date.new(f.object.member_since.to_i), {:start_year => 2013, :end_year => 1920, :field_name => 'member_since', :prompt => 'Choose year', prefix: :member}, {:class => "form-control"} ) %>

Bootstrap text_area width under haml

I have a Rails app and am using haml and bootstrap. One my form I have two fields for entering text, and only one is displayed, depending on a variable I set in the controller. If there is a text area I would like to size it, and the :rows attribute works but not columns.
I have also tried to use %div :class => 'span6' to widen the text_area, but it doesn't seem to work.
= form_for [#lesson_layout, #layout_field] do |f|
.field
= f.label :field_name
= f.text_field :field_name
- case #layout_type
- when "Text Field"
.field
= f.label :field_value
= f.text_field :field_value
- when "Text Area"
.field
= f.label :field_value_long
= f.text_area :field_value_long, :rows => 5, :placeholder => 'Enter text.'
.actions
= f.submit
EDIT
Tried the following code, and it did not change the size of the box.
.field
= f.label :field_value_long
= f.text_area :field_value_long, :rows => 5, :placeholder => 'Enter text using markdown.', :html => { :style => "width:300em" }
Something like this should work :
= f.text_area :field_value_long, :rows => 5, :class => "span6", :placeholder => 'Enter text.'
f.text_area(
:field_value_long,
:rows => 5,
:placeholder => 'Enter text.',
:html => { :style => "width:20em !important" }
)
OR
f.text_area(
:field_value_long,
:rows => 5,
:placeholder => 'Enter text.',
:html => { :class => "my_wide_class" }
)

Resources