Rails Date Picker Error - ruby-on-rails

I am using the following gem in my rails app - https://github.com/TrevorS/bootstrap3-datetimepicker-rails.
My form looks as follows:
<%= simple_form_for([#customer,#job], html: {class:'form-horizontal'}, wrapper: :horizontal_form) do |f| %>
<%= f.input :install, collection: ["Yes", "No"], input_html: {class:'form-control'}, prompt: "Installing?" %>
<%= f.input :delivery, collection: ["Yes", "No"], input_html: {class:'form-control'}, prompt: "Delivering?" %>
<%= f.input :job_tag, input_html: {class:'form-control'} %>
<%= f.input :install_date, :as => :date_picker, input_html: { class: "datepicker"} %>
<%= f.input :box_count, input_html: {class:'form-control'} %>
<%= f.input :cabinet_cost, input_html: {class:'form-control'} %>
<%= f.input :counter_top_cost, input_html: {class:'form-control'} %>
<%= f.input :install_cost, input_html: {class:'form-control'} %>
<br />
<%= f.button :submit, "Create Job", class: "col-md-3 bump-right" %>
<% end %>
When I submit the form I get the following error:
I18n::ArgumentError in Jobs#create
Object must be a Date, DateTime or Time object. "29/08/2014" given.
Does anyone know why this error is thrown and how I fix this?

The column in your database for install_date needs to be a date or datetime type. It looks like you are storing the date as a string instead.

Related

Checking simple_form f.input value before submitting the form

I have this form:
<%= simple_form_for(#student) do |f| %>
<%= f.input :first_name, label: "Nombre" %>
<%= f.input :hours_studying, as: :select, collection: [1, 2],
prompt: 'Horas' %>
<%= f.input :library_id, as: :select, collection: #libraries %>
<div class="text-center">
<%= f.button :submit, "Regístrame!", class: "btn button rounded-pill
p-3 my-4 fs-18 shadow" %>
</div>
<% end %>
Libraries have a country and a city, how could I add two fields to the form to check the country and the city and filter the libraries accordingly?

Simple_form and association

I have this form:
<%= simple_form_for #request, html: {class: 'form-horizontal' } do |f| %>
<%= f.input :initiator, label: 'initiator' %>
<%= f.association :department, collection: Department.all, value_method: :id, label: 'Назначить на отдел' %>
<%= f.association :user, collection: User.all, label_method: :email, label: 'Ответственный' %>
<%= f.input :comment, label: 'comment' %>
<%= f.input :sla, label: 'SLA' %>
<%= f.button :submit, label: 'Создать', class: "btn btn-primary" %>
<% end %>
How can I make the association:
If I choose "Department 1" from: Department, the choice of the :user will only users who belong to this department. (When you open the drop-down list were only people from the Department 1, not Users.all) What parameters I have to pass the rails?
I doubt if it is possible only using simple_form
Try http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/
I would advice against loading all users in DOM, use an ajax action to filter users if they are many

Using Foundation Data Abide Validations in Modal (AJAX) doesn't Validate. `

I can't get Data Abide to validate my fields in a modal (Foundation 5, Simple Form, Ruby on Rails).
Anyone know how to validate fields in a modal with AJAX using data-abide from Foundation?
<%= simple_form_for [current_user, #photo, #tag], id: "tagform", :remote => true do |f| %>
<div class="center semi_padding new_tag_form">
<%= f.input :name , label: "Marca: ", :required => "[a-zA-Z]+" ,input_html: {class: 'marca ipt'} %>
<%= f.input :location, label: "¿Donde lo encontraste?" , input_html: {class: 'ipt'} %>
<%= f.input :price, label: "¿Cuanto te costó?" , input_html: {class: 'ipt'} %>
<%= f.input :coordinate_x , as: :hidden %>
<%= f.input :coordinate_y , as: :hidden %>
<%= f.button :button, "Taggear", type: "button", id:"tp_tag_save", input_html: {class: 'btn-ok icon-favorite-1 button'} %>
<%= f.button :button, "Cancelar", name: "Cancel", id: "tp_tag_cancel", input_html: {class: 'icon-cancel button'} %>
</div>
<% end %>
Add this to your simple_form tag:
html: {novalidate: "novalidate", data: {abide: ''}
EX:
<%= simple_form_for [current_user, #photo, #tag], id: "tagform", :remote => true, html: {novalidate: "novalidate", data: {abide: ''} do |f| %>
Then make sure to throw in a reflow call on the form when the modal is triggered by adding the following JS to the click handler:
$(document).foundation('abide', 'reflow');

Select element, simple_form helper

I am trying to create an element in my form that uses simple form+bootstrap. The idea is to allow a user select a type of currency from a drop down.
Customer_currency to select from either USD- US Dollars, LRD - Liberian dollar among others.
I have used the following in my form
However, it is not working, all I see is a drop down (out of position) in my form with the options but no label.
How can i create a good select element with a label using simple form
<%= simple_form_for #customer, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name %>
<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %>
<%= f.input :payment_terms %>
<%= f.input :billing_address %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :mobile %>
<%= f.input :email %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
customers_path, :class => 'btn' %>
</div>
<% end %>
<%= f.input :customer_currency, :collection => [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %>
Add label_method and value_method to your select, means change:
<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]] %>
to:
<%= f.select :customer_currency, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]], label_method: :first, value_method: :last %>
Update: other solution
<%= f.input :customer_currency, as: :select, [['UGX- Uganda Shillings',1],['USD- US Dollars',2]], label_method: :first, value_method: :last %>

Rails: Issue with simple_form

I've built a simple_form form in my rails app and things went just fine:
<%= simple_form_for([#folha, #servico], html: {class: 'well form-horizontal'}) do |f| %>
<%= f.association :pessoa, label: 'Funcionário' %>
<%= f.input :funcao, label: 'Função',collection: #funcoes %>
<%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
<%= f.input :valor, label: 'Valor por hora', as: :string ,input_html: {class: 'span1'} %>
<%= f.input :horas, as: :string, input_html: {class: 'span1'} %>
<%= f.button :submit, 'Incluir', class: 'btn btn-primary' %>
<% end %>
To change the order list on the dropdown for the f.association i've overwritten the default .all method in Pessoa.rb:
def self.all
order :nome
end
Then i got this error when trying to render my view:
wrong number of arguments (1 for 0)
Extracted source (around line #5):
2: <h1>Preencher Pagamentos - Folha <%= "#{#folha.mes}/#{#folha.ano}" %> <small> <%= #folha.obs %> </small> </h1>
3: </div>
4: <%= simple_form_for([#folha, #servico], html: {class: 'well form-horizontal'}) do |f| %>
5: <%= f.association :pessoa, label: 'Funcionário' %>
6: <%= f.input :funcao, label: 'Função',collection: #funcoes %>
7: <%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
I think its better find a way to order the list in the view. But im very curious about what
is going on...
You should not override those kind of methods in first place.
Here is how to do it with simple_form
f.association : pessoa, :collection => Pessoa.order(:nome).all
https://github.com/plataformatec/simple_form/#associations
You can use default_scope as described here.
Use this macro in your model to set a default scope for all operations on the model.
In your case default_scope order(:nome).

Resources