I have created a HTML form which works fine on my development and staging servers, however it is not working on the production environment.
Staging and production server URLs can be reached below:
Staging
Production
I am quite new to Rails and I will appreciate any kind of support. Below you can find the form code in the view template:
<%= form_for(#referral_form, url: submit_referral_form_url, method: :post, :remote => true ) do |f| %>
<div class="contact-us-error"><ul></ul></div>
<div class="form-group has-success has-feedback">
<%= f.text_field :name, :class=>"form-control", :placeholder => "Adınız & Soyadınız", required: true %>
<span class="glyphicon glyphicon-user form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-success has-feedback">
<%= f.text_field :phone, :class=>"form-control", :placeholder => "Telefon Numaranız", required: true %>
<span class="glyphicon glyphicon-phone form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-success has-feedback">
<%= f.text_field :friend_name, :class=>"form-control", :placeholder => "Arkadaşınızın Adı & Soyadı", required: true %>
<span class="glyphicon glyphicon-user form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-success has-feedback">
<%= f.text_field :friend_phone, :class=>"form-control", :placeholder => "Arkadaşınızın Telefon Numarası", required: true %>
<span class="glyphicon glyphicon-phone form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-success has-feedback">
<%= f.email_field :email, :class=>"form-control" , type:'email', required: true, placeholder: "Email Adresiniz" %>
<span class="glyphicon glyphicon-envelope form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-success has-feedback">
<%= f.text_area :message, :class=>"form-control", :placeholder=>"Arkadaşınızın Arabasının Özelliği (Yıl, Marka, Model vb)", required: true %>
</div>
<div class="form-group has-success has-feedback">
<%= f.hidden_field :campaign_name, :value => "Nusret-2017"%>
</div>
<div class="form-group has-success has-feedback">
<%= f.submit "Gönder", class: "btn createaccbtn" %>
</div>
<% end %>
If you can use a relative path then just change submit_referral_form_url to submit_referral_form_path
Related
Hopefully someone can help me out with this! I am trying to implement stripe elements in rails and basically what I have is an Orders class, but the person checking out has the option to choose between two forms... the first form has two additional field options for them to fill out if the click this option. The second option has two less fields to fill out in the order form. Right now I am rendering this form as a partial and I am restricting whether or not the two conditional fields are shown by passing a local to the form partial. This is all working great. What is NOT working, is that my Stripe elements tag is rendering fine on the first form render, but it never renders in a functional state or with any css styles on the second form. The stripe_elements_tag in the second rendered version of the tag is totally useless. Can anyone think of a better way to do this or a fix that might work? I tried hiding the content in the divs and displaying it with an on click, show the form, but this also did not work. The second form would never be shown ( i noticed this option also made the form animations slower :( .
At this point I am considering actually just writing two separate forms even though thats not very DRY just to see if it will work that way.
Any ideas or thoughts are very much welcomed!
Have a great day everyone!
here is my new.html.erb code
<%= stripe_javascript_tag %>
<div class="container">
<div class="mx-auto" width="400px">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Referred By Group
</button>
</h5>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
<%= render "order_form", locals: { buy_method: "group" } %>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Purchasing Independently
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<%= render "order_form", locals: { buy_method: "individual" } %>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6" id="flash-message">
<%= render partial: 'flash' %>
<% #order.errors.full_messages.each do |msg| %>
<li> * <%= msg %> </li>
<% puts msg %>
<% end %>
</div>
<div class="row">
<div class="col-md-9 mb-md-0 mb-5">
<%= form_for #order do |f| %>
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :customer_name, "Your Name *" %><br />
<%= f.text_field :customer_name, class: "form-control" %>
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :email, "Email *" %><br />
<%= f.text_field :email, class: "form-control" %>
</div>
</div>
</div>
<% if locals[:buy_method] == "group"%>
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :student_name, "Student Name *" %><br />
<%= f.text_field :student_name, class: "form-control" %>
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :school_name, "School or Group Name *" %><br />
<%= f.text_field :school_name, class: "form-control"%>
</div>
</div>
</div>
<% end %>
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :street_address, "Street Address *" %><br />
<%= f.text_field :street_address, class: "form-control" %>
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :number_books, "Number of books to purchase *" %><br />
<%= f.select :number_books, (0..99), class: "form-control", selected: 0%>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :city, "City *" %><br />
<%= f.text_field :city, class: "form-control" %>
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :state, "State *" %><br />
<%= f.select :state, [ "--",'AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FM', 'FL', 'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MH', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PW', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VI', 'VA', 'WA', 'WV', 'WI', 'WY' ], class: "form-control"%>
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
<%= f.label :zip_code, "Zip code *" %><br />
<%= f.text_field :zip_code, class: "form-control" %>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<div class="checkbox">
<%= f.check_box :email_permission, checked: "checked", checked_value: true, unchecked_value: false %>
<%= f.label :email_permission, class: "checkbox-inline" %>
</div>
</div>
</div>
<div class="form-group">
<label for="card-element">Credit or debit card *</label>
<div id="card-element" class="form-control" >
<%= stripe_elements_tag submit_path: contact_index_path %>
</div>
</div>
<div class="form-group">
<%= f.label :total %>
<%= f.label :total, id: "total", value: "$#{ #order.total }" %>
</div>
<%= f.submit "Submit", class: "btn btn-default btn-primary" %>
</div>
<% end %>
</div>
</div>
You need to create two separate Instances of the card referencing your stripe api_key two separate times. You cannot create two elements using the same instantiation of your stripe api key.
I'm building out a form on a Rails app and for one of the sections I'm getting some random text in the text field (School Group) and I'm not sure why -
This is the code for the form, am I using the wrong type of field?
<% provide :title, "Add Staff Member" %>
<%= form_for #user do |f| %>
<div class="form-group row">
<%= f.label :firstname, 'First Name', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.text_field :firstname, class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :nickname, 'Nickname', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.text_field :nickname, class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :surname, 'Last Name', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.text_field :surname, class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :email, 'Email Address', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.email_field :email, class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :email, 'Send Welcome Email?', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= check_box_tag :send_welcome_email %>
</div>
</div>
<div class="form-group row">
<%= f.label :user_groups, 'School Group', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.text_field :user_groups, class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :timezone, 'Timezone', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.time_zone_select(:timezone, nil, {default: #user.timezone}, {class: 'form-control custom-select'}) %>
</div>
</div>
<hr>
<h2>Create Password</h2>
<p><small>Password must be at least six characters long</small></p>
<div class="form-group row">
<%= f.label :password, 'New Password', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group row">
<%= f.label :password_confirmation, 'Confirm Password', class: 'col-sm-2' %>
<div class="col-sm-10">
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="actions">
<%= f.submit 'Submit', class: 'btn btn-primary' %>
</div>
<% end %>
The field for school groups can actually be left blank for the benefit of this form but I want the field there. How do I get rid of this text?
it's not some random text it might be a association in your User or #user probably column name is named same as the association name or may be a typeo.
I'm using devise on my project, i want to update others profile from my admin panel, so only users with admin role can access it, since this behavior is very different to the default devise, i decided to create a separated controller, so i can manipulate users as normal records, but for some reason when i update users, the records are not updated into the database.
THESE ARE MY ROUTES
devise_for :users, controllers: { registrations: 'users/registrations' }
root "users#index"
post "users/:id" => "users#show"
get "users/:id" => "users#show", as: :user
patch "users/:id" => "users#show"
resources :receipts
resources :notes
get "users/edit/:id" => "users#edit", as: :edit_user
THIS IS MY CONTROLLER
def edit
#user = User.find(params[:id])
end
def update
user = User.find(params[:id])
user.update(user_update_params)
redirect_to user
end
private
def user_update_params
params.require(:user).permit(:username, :names, :last_names, :guardian, :phone, :identification, :role)
end
def user_params
if #user.debts.nil?
params.require(:user).permit(:debts)
else
params.require(:user).permit(:add_debt)
end
end
THESE IS MY VIEW
<% if current_user && current_user.has_role?(:admin) %>
<div class="container form-bg">
<div class="row main">
<div class="panel-heading">
<div class="panel-title text-center">
<h1 class="title">Editar usuario</h1>
<hr />
</div>
</div>
<div class="main-login main-center">
<%= form_for #user do |f| %>
<div class="form-group">
<%= f.label :username, "Usuario" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :username, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :names, "Nombres" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :names, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :last_names, "Apellidos" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :last_names, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :phone, "Teléfono" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<%= f.text_field :phone, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :identification, "Número de identification" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<%= f.text_field :identification, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :guardian, "Guardian legal" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :guardian, autofocus: true, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group ">
<label>
<%= f.radio_button :role, "student" , :checked => true %>
Estudiante
</label>
<label>
<%= f.radio_button :role, "teacher" %>
Profesor
</label>
</div>
<div class="form-group">
<%= f.label :password, "Contraseña" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %>
<%= f.password_field :password, autofocus: true, class: "form-control", autocomplete: "off" %>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :password_confirmation, "Confirmar contraseña" ,class: "cols-sm-2 control-label" %><br />
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa" aria-hidden="true"></i></span>
<%= f.password_field :password_confirmation, autofocus: true, class: "form-control", autocomplete: "off" %>
</div>
</div>
</div>
<div class="form-group ">
<%= f.submit "Editar", class: "btn btn-primary btn-lg btn-block login-button" %>
</div>
<% end %>
</div>
</div>
<p class="invisible">asdsadsadsdsadsad</p>
</div>
<% else %>
<h1>Acceso exclusivo para administradores</h1>
<% end %>
So after reading my stack trace, it indeed tries to make the patch, but then it says that the params are not permitted, which is very weird since i already did permit them on my user_update_params method.
this what appears on my trace
Started PATCH "/users/12" for ::1 at 2017-01-28 13:20:53 -0500
Processing by UsersController#show as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"IdJKYYFVh8ZJJm/RPRJd7blfQw84Ct38KjE5tZ6fTuHFK8TG04MxUu2OtQv6wfLvFJll0EYYZa+ooxP19RqOAQ==", "user"=>{"username"=>"jimena", "names"=>"Jimena44", "last_names"=>"Delgado Díaz44", "phone"=>"214123244", "identification"=>"32312", "guardian"=>"3213123", "role"=>"student", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Editar", "id"=>"12"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 12]]
Unpermitted parameters: username, names, last_names, phone, identification, guardian, role, password, password_confirmation
So why are my files not being updated if it even redirects as it is intended on the controller?
Thanks for reading.
Since you are using devise I think you need to set it up like this:
before_action :configure_permitted_parameters
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update) << [:username, :names]
end
Make sure the controller is inheriting from devise:
class UsersController < Devise::RegistrationsController
You can read more about it here and here, in the parts about strong parameters.
In my edit view, I want to apply bootstrap. However, when replacing...
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="row">
<div class="col-md-6">
<div class="row form-group">
<div class="col-md-4"><%= f.label :username %></div>
<div class="col-md-8"><%= f.text_field :username %></div>
</div>
with this...
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="sr-only" for="username">Username</label>
<input type="text" class="form-control" name="username" placeholder="Username" value="<%= f.text_field :username %>">
</div>
</div>
</div>
I get this as output
I have tried many alternatives to include erb but don't understand the issue. How should I include the field in my edit forms?
you can do all the things with rails.
<div class="row">
<div class="col-md-4">
<div class="form-group">
<%= f.label :username %>
<%= f.text_field :username, class: "form-control", placeholder: "Username" %>
</div>
</div>
</div>
For more detail Please visit this link
http://apidock.com/rails/ActionView/Helpers/FormHelper/text_field
If you want to use add-on you can as below
<div class='input-group' >
<%= f.text_field :username, class: "form-control", placeholder: "Username" %>
<span class="input-group-addon" id="basic-addon2">#example.com</span>
</div>
Try this instead
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="sr-only" for="username">Username</label>
<%= f.text_field :username, class: "form-control", placeholder: "Username" %>
</div>
</div>
</div>
I would suggest using a gem called simple_form, it's made by the creators of Devise and works nicely with Bootstrap. It also has nice validation errors.
https://github.com/plataformatec/simple_form
Here's an example:
= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
.form-inputs
= f.input :email, required: false, autofocus: true, placeholder: 'Email'
= f.input :password, required: false, placeholder: 'Password'
= f.input :remember_me, as: :boolean, label: 'Remember Me' if devise_mapping.rememberable?
.form-actions
= f.button :submit, 'Sign in', class: 'btn-block btn-success'
%br
= link_to 'Forgot your password?', new_user_password_path
The code above will automatically add any bootstrap classes and labels...etc
If I have a rails field like:
<div class="field form-group">
<%= f.label :x_size, class: 'col-sm-1 control-label' %>
<div class="col-sm-3">
<%= f.text_field :x_size, class: 'form-control' %>
</div>
</div>
<div class="actions form-group">
<div class="col-sm-2">
<%= f.submit 'Submit', :class => 'btn btn-primary' %>
</div>
</div>
How would I validate the submit button to work only on numeric inputs?
Try this:
number_field
Docs here