I am new to rails, And stuck in this problem from last two days
I have a student and student_parent model they have a one-to-many relationship i want to build database attribute through one object from form to datase.
controller's method
def new
#student = Student.new
1.times{ #student.student_parents.build }
.....
.....
end
Create Method:-
def create
#student = Student.new(params[:student])
respond_to do |format|
if #student.save
format.html { redirect_to Student, notice: 'Student was successfully created.' }
format.json { render json: #student, status: :created, location: #student }
else
format.html { render action: "new" }
format.json { render json: #student.errors, status: :unprocessable_entity }
end
end
end
Model:-
class Student < ActiveRecord::Base
include ErrorMessages
belongs_to :user
has_many :student_parents
attr_accessible :birth_date, :blood_group, :first_name, :gender, :last_name, :middle_name,
:school_name, :student_rollno, :email, :user_id, :student_parents_attributes
accepts_nested_attributes_for :student_parents
end
form:-
<%= simple_form_for #student, :html => { :class => 'form-horizontal' } do |f| %>
<div class="row-fluid">
<div class="span3">
<%= f.label :first_name, :class => 'control-label',:required => true %>
<%= f.text_field :first_name %>
</div>
<div class="span3">
<%= f.label :middle_name, :class => 'control-label'%>
<%= f.text_field :middle_name %>
</div>
<div class="span3">
<%= f.label :last_name, :class => 'control-label',:required => true %>
<%= f.text_field :last_name %>
</div>
</div>
<div class="control-group">
<label class = "control-label"> Email </label>
<div class="controls">
<%= f.text_field :email, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<label class = "control-label"> Birth Date <abbr title="required">*</abbr></label>
<div class="controls">
<%= f.text_field :birth_date, :class => 'text_field' ,'data-behaviour' => 'datepicker' %>
</div>
</div>
<% model_class = StudentParent %>
<div class="page-header">
<h4> Parent Information</h4>
</div>
<%= f.fields_for :student_parents do |student_parent| %>
<div class="row-fluid">
<!--<div class="span9">-->
<h5> Father Name </h5>
<div class="span3">
<%= student_parent.label :first_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :first_name %>
</div>
<div class="span3">
<%= student_parent.label :middle_name, :class => 'control-label'%>
<%= student_parent.text_field :middle_name %>
</div>
<div class="span3">
<%= student_parent.label :last_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :last_name %>
</div>
</div>
<div class="row-fluid">
<h5> Mother Name </h5>
<div class="span3">
<%= student_parent.label :first_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :first_name %>
</div>
<div class="span3">
<%= student_parent.label :middle_name, :class => 'control-label'%>
<%= student_parent.text_field :middle_name %>
</div>
<div class="span3">
<%= student_parent.label :last_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :last_name %>
</div>
</div>
<% end %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
students_path, :class => 'btn' %>
</div>
when submit it only build student information in student table and mother information in student_parent table. But it miss the parent information.
Related
So I have this book edit page which contains unique fields(Title, ISBN). But before I submit the form to update, I need to send first the form information to another confirmation page and then update. But when I pass the form info to the confirmation page, the unique validations for Title and ISBN fails. I have this code:
book.rb
validates :title, presence: true,
uniqueness: true
validates :isbn, presence: true,
uniqueness: true,
format: { with: /[0-9]/ }
edit.html.erb
<%= form_for #book, url: confirm_edit_admin_book_path, method: :patch, html: { class: "form" } do |f| %>
<%= f.hidden_field :id %>
<div class="float-right">
<button class="btn btn-primary">Confirm</button>
</div>
<h4 class="card-title">Edit Book</h4>
<div class="form-group row mt-5">
<%= f.label :title, class: "col-md-2 col-form-label required" %>
<div class="col-md-10">
<%= f.text_field :title, class: "form-control" %>
<%= render "admin/shared/error_field", field: :title %>
</div>
</div>
<div class="form-group row">
<%= f.label :isbn, "ISBN", class: "col-md-2 col-form-label required" %>
<div class="col-md-10">
<%= f.text_field :isbn, class: 'col-sm-12 form-control' %>
<%= render "admin/shared/error_field", field: :isbn %>
</div>
</div>
<div class="form-group row">
<%= f.label :released_at, class: "col-md-2 col-form-label required" %>
<div class="col-md-10">
<%= f.date_field :released_at, class: 'col-sm-12 form-control' %>
<%= render "admin/shared/error_field", field: :released_at %>
</div>
</div>
<div class="form-group row">
<%= f.label :description, class: "col-md-2 col-form-label" %>
<div class="col-md-10">
<%= f.text_area :description, class: 'col-sm-12 form-control' %>
<%= render "admin/shared/error_field", field: :description %>
</div>
</div>
<div class="form-group row">
<%= f.label :quantity, class: "col-md-2 col-form-label required" %>
<div class="col-md-10">
<%= f.number_field :quantity, class: 'col-sm-12 form-control' %>
<%= render "admin/shared/error_field", field: :quantity %>
</div>
</div>
<div class="float-right">
<%= f.submit "Confirm", class: "btn cur-p btn-primary" %>
</div>
<% end %>
books_controller.rb
def confirm_edit
#book = Book.new(book_params)
book_info = Book.find(#book.id)
if #book.valid?
session[:book_update] = #book
else
render 'edit'
end
end
def update
#book = Book.find(params[:id])
#book.update_attributes(session[:book_update].compact)
session.delete(:book_update)
redirect_to admin_book_url
end
In the confirm_edit action you are creating a new instance of Book using the params from the update action, which are presumably the params from an existing book.
#book = Book.new(book_params)
You are then calling #book.valid? which is going to fail (unless you've changed the Title and ISBN) because a book with the same values is already in the database.
You could retrieve the book from the database and then use .assign_attributes to check validity that way perhaps?
def confirm_edit
#book = Book.find(params[:id])
#book.assign_attributes(book_params)
if #book.valid?
session[:book_update] = #book
else
render 'edit'
end
end
I would like to update my stock check every day. So I have Ingredient table in my database also have IngredietnStockChek where every day I would like to save my stock check.
My idea is to create form who will show me input field quantity for every product I've got and then on this form I'll put how much I have.
<%= form_for(#stock_of_ingredient, :multipart => true, html: { class: "form-horizontal", role: "form" }) do |f| %>
<% #ingredients.each do |b| %>
<%= fields_for "stock_of_ingredients" do |c| %>
<div class="form-group">
<%= c.label "#{b.name}", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= c.number_field :ingredient_id, class: "form-control", value: "#{b.id}" %>
</div>
</div>
<div class="form-group">
<%= c.label :quantity, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= c.text_field :quantity, class: "form-control" %>
</div>
</div>
<div class="form-group">
<%= c.label :todays_date, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= c.date_select :todays_date, class: "form-control" %>
</div>
</div>
<% end %>
<% end %>
So this is my form should I use
<%= fields_for "stock_of_ingredients" do |c| %>`
Or should I
<%= fields_for "stock_of_ingredients[]" do |c| %>
To catch all data from all fields
And how to modify controller create action to save all, I should probably use loop but how.
def create
#stock_of_ingredient = StockOfIngredient.new(stock_of_ingredient_params)
respond_to do |format|
if #stock_of_ingredient.save
format.html { redirect_to #stock_of_ingredient, notice: 'Stock of ingredient was successfully created.' }
format.json { render :show, status: :created, location: #stock_of_ingredient }
else
format.html { render :new }
format.json { render json: #stock_of_ingredient.errors, status: :unprocessable_entity }
end
end
end
As far as I understand what you're doing, I think you can use fields_for:
<%= form_tag update_my_ingredients_for_a_product_path, method: :put do %>
<% #ingredients.each do |b| %>
<%= fields_for "ingredients[]", b do |f| %>
<div class="form-group">
<%= f.label "#{b.name}", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.number_field :ingredient_id, class: "form-control", value: "#{b.id}" %>
</div>
</div>
...
<% end %>
<%= submit_tag "Save", class: "btn btn-default" %>
<% end %>
Documentation for fields_for
Railscast close to your question
Below is my api model:
class Api < ActiveRecord::Base
validates_presence_of :name
belongs_to :service
has_many :statuses
accepts_nested_attributes_for :statuses, reject_if: proc { |attributes| attributes['name'].blank? }
end
Below is my description model:
class Description < ActiveRecord::Base
validates_presence_of :value
belongs_to :status
end
Below is my status model:
class Status < ActiveRecord::Base
belongs_to :api
has_many :descriptions
accepts_nested_attributes_for :descriptions, reject_if: proc { |attributes| attributes['value'].blank? }
end
And below is my new and create action of controller:
def new
#api = Api.new
#status = #api.statuses.new
#status.descriptions.new
end
def create
#api = Api.new(api_params)
if #api.save
flash[:info] = request.original_url + ".do?apiname=" + "#{#api.name}"
redirect_to root_path
else
#api.statuses.new
render :new
end
private
def api_params
params.require(:api).permit(:name, statuses_attributes: [:name, descriptions_attributes:[:value]])
end
Below is my new template:
<div class="form-horizontal">
<%= form_for #api, :url => commons_path do |f| %>
<div class="form-group">
<%= f.label :name, "API Name", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :statuses do |status| %>
<div class="form-group">
<%= status.label :name, "Status", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= status.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :description do |description| %>
<div class="form-group">
<%= description.label :value, "Body", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= description.text_area :value, class: "form-control", rows: 12, cols: 65 %>
</div>
</div>
<% end %>
<% end %>
<%= f.submit("Create Data", class: 'btn btn-primary col-sm-offset-2') %>
<%= link_to "Cancel", root_path, class: "btn btn-danger" %>
<% end %>
After I create new data.It seems like only description's value did not save to my data base. and find an error "Unpermitted parameter: description" in my console.
Any one know what happen?
<div class="form-horizontal">
<%= form_for #api, :url => commons_path do |f| %>
<div class="form-group">
<%= f.label :name, "API Name", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :statuses do |status| %>
<div class="form-group">
<%= status.label :name, "Status", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= status.text_field :name, class: "form-control" %>
</div>
</div>
<%= status.fields_for :descriptions do |description| %>
<div class="form-group">
<%= description.label :value, "Body", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= description.text_area :value, class: "form-control", rows: 12, cols: 65 %>
</div>
</div>
<% end %>
<% end %>
<%= f.submit("Create Data", class: 'btn btn-primary col-sm-offset-2') %>
<%= link_to "Cancel", root_path, class: "btn btn-danger" %>
<% end %>
previously i was able to download whwn i uploaded single file, but when i changed it to multiple file upload i was unabel to download please help me out
here is my controller
invoice_details_controller.rb
class InvoiceDetailsController < ApplicationController
before_action :set_invoice_detail, only: [:show, :edit, :update, :destroy]
respond_to :html
def index
#invoice_details = InvoiceDetail.all
respond_with(#invoice_details)
end
def show
#invoice_detail = InvoiceDetail.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => #invoice_detail }
format.pdf { render :layout => false }
end
end
def new
#invoice_detail = InvoiceDetail.new
respond_with(#invoice_detail)
end
def edit
end
def create
#invoice_detail = InvoiceDetail.new(invoice_detail_params)
respond_to do |format|
if #invoice_detail.save
format.html { redirect_to invoice_details_path, notice: 'Invoice was successfully created.' }
else
format.html { render action: "new" }
end
end
end
def update
#invoice_detail.update(invoice_detail_params)
redirect_to invoice_details_path
end
def destroy
#invoice_detail.destroy
redirect_to invoice_details_path
end
def download
respond_to do |format|
format.html {
if params[:invoice_id].nil?
redirect_to :back
else
begin
invoice = InvoiceDetail.find(params[:invoice_id])
attachment_file = File.join('public', invoice.attachment.url)
if File.exists?(attachment_file)
send_file attachment_file, :disposition => 'attachment'
else
redirect_to :back
end
rescue Exception => error
redirect_to :back
end
end
}
end
end
private
def set_invoice_detail
#invoice_detail = InvoiceDetail.find(params[:id])
end
def invoice_detail_params
params.require(:invoice_detail).permit(:attachment,:invoice_number, :supplier_name, :invoice_date, :invoice_due_date, :description_of_goods, :quatity, :price_per_unit, :total_amount, :mode_of_payment, :status, :shipping_country)
end
end
here are my models
invoice_details.rb
class InvoiceDetail < ActiveRecord::Base
has_many :attachment
accepts_nested_attributes_for :attachment
end
invoice_files.rb
class InvoiceFile < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
belongs_to :InvoiceDetail
validates :name, presence: true # Make sure the owner's name is present.
end
here is my form
_form.html.erb
<%= form_for(#invoice_detail , html: {class: 'form-horizontal', role: 'form' }) do |f| %>
<% if #invoice_detail.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#invoice_detail.errors.count, "error") %> prohibited this invoice_detail from being saved:</h2>
<ul>
<% #invoice_detail.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :invoice_number, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :invoice_number, :class => 'text_field', :required => true, :maxlength => 15, :placeholder =>'15 Alpha Numeric with special Characters', :presence => "check invoice num" %>
</div>
</div>
<div class="field">
<%= f.label :supplier_name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :supplier_name, :class => 'text_field', :required => true,:maxlength => 20, :placeholder => '20 Alpha numeric characters' %>
</div>
</div>
<div class="field">
<%= f.label :invoice_date, :class => 'control-label' %>
<div class="controls1">
<%= f.date_select :invoice_date, :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :invoice_due_date, :class => 'control-label' %>
<div class="controls1">
<%= f.date_select :invoice_due_date, :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :description_of_goods, :class => 'control-label' %>
<div class="controls">
<%= f.text_area :description_of_goods, :class => 'text_area', :maxlength => 50, :placeholder => 'Accepts up to 50 Alpha Numeric with special Characters'%>
</div>
</div>
<div class="field">
<%= f.label :quality, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :quatity , :class => 'text_area',:maxlength => 10, :placeholder =>'Accepts up to 10 Digits'%>
</div>
</div>
<div class="field">
<%= f.label :price_per_unit, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :price_per_unit, :class => 'text_area',:maxlength => 15, :placeholder =>'Accepts up to 15 Digits' %>
</div>
</div>
<div class="field">
<%= f.label :total_amount, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :total_amount, :class => 'text_area', :maxlength => 15, :placeholder =>'Accepts up to 15 Digits' %>
</div>
</div>
<div class="field">
<%= f.label :mode_of_payment, :class => 'control-label' %>
<div class="controls">
<%= f.select :mode_of_payment, options_for_select(%w[Cash Cheque Transfer LC]), :class => 'text_area', :placeholder => 'Select mode of payment' %>
</div>
</div>
<div class="field">
<%= f.label :status, :class => 'control-label' %>
<div class="controls">
<%= f.select :status, options_for_select(%w[Paid Pending]), :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :shipping_country, :class => 'control-label' %>
<div class="controls">
<%= f.country_select :shipping_country, {priority: %w(ID US CA), prompt: 'Please select a country'}, :class => 'text_area' %>
</div>
</div>
<div class="control-group">
<%= f.label :attachment , :class => 'control-label' %>
<div class="controls">
<%= f.file_field :avatar, :multiple => true, name: "attachment[avatar][]", :class => 'file_field', :required => true %>
</div>
</div>
<div class="form-actions1">
<%= f.submit :class => 'btn btn-primary' %>
<%#= f.submit "cancel", :class => 'btn btn-danger', method: :delete, data: { confirm: 'Are you sure you want to cancel' } %>
<%= form_for(#invoice_detail , html: {class: 'form-horizontal', role: 'form' }) do |f| %>
<% if #invoice_detail.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#invoice_detail.errors.count, "error") %> prohibited this invoice_detail from being saved:</h2>
<ul>
<% #invoice_detail.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :invoice_number, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :invoice_number, :class => 'text_field', :required => true, :maxlength => 15, :placeholder =>'15 Alpha Numeric with special Characters', :presence => "check invoice num" %>
</div>
</div>
<div class="field">
<%= f.label :supplier_name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :supplier_name, :class => 'text_field', :required => true,:maxlength => 20, :placeholder => '20 Alpha numeric characters' %>
</div>
</div>
<div class="field">
<%= f.label :invoice_date, :class => 'control-label' %>
<div class="controls1">
<%= f.date_select :invoice_date, :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :invoice_due_date, :class => 'control-label' %>
<div class="controls1">
<%= f.date_select :invoice_due_date, :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :description_of_goods, :class => 'control-label' %>
<div class="controls">
<%= f.text_area :description_of_goods, :class => 'text_area', :maxlength => 50, :placeholder => 'Accepts up to 50 Alpha Numeric with special Characters'%>
</div>
</div>
<div class="field">
<%= f.label :quality, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :quatity , :class => 'text_area',:maxlength => 10, :placeholder =>'Accepts up to 10 Digits'%>
</div>
</div>
<div class="field">
<%= f.label :price_per_unit, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :price_per_unit, :class => 'text_area',:maxlength => 15, :placeholder =>'Accepts up to 15 Digits' %>
</div>
</div>
<div class="field">
<%= f.label :total_amount, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :total_amount, :class => 'text_area', :maxlength => 15, :placeholder =>'Accepts up to 15 Digits' %>
</div>
</div>
<div class="field">
<%= f.label :mode_of_payment, :class => 'control-label' %>
<div class="controls">
<%= f.select :mode_of_payment, options_for_select(%w[Cash Cheque Transfer LC]), :class => 'text_area', :placeholder => 'Select mode of payment' %>
</div>
</div>
<div class="field">
<%= f.label :status, :class => 'control-label' %>
<div class="controls">
<%= f.select :status, options_for_select(%w[Paid Pending]), :class => 'text_area' %>
</div>
</div>
<div class="field">
<%= f.label :shipping_country, :class => 'control-label' %>
<div class="controls">
<%= f.country_select :shipping_country, {priority: %w(ID US CA), prompt: 'Please select a country'}, :class => 'text_area' %>
</div>
</div>
<div class="control-group">
<%= f.label :attachment , :class => 'control-label' %>
<div class="controls">
<%= f.file_field :avatar, :multiple => true, name: "attachment[avatar][]", :class => 'file_field', :required => true %>
</div>
</div>
<div class="form-actions1">
<%= f.submit :class => 'btn btn-primary' %>
<%#= f.submit "cancel", :class => 'btn btn-danger', method: :delete, data: { confirm: 'Are you sure you want to cancel' } %>
<%= link_to "Cancel", invoice_details_path(), :class => 'btn btn-danger', data: { confirm: 'Are you sure you want to cancel' } %>
</div>
<% end %>
<%= link_to "Cancel", invoice_details_path(), :class => 'btn btn-danger', data: { confirm: 'Are you sure you want to cancel' } %>
</div>
<% end %>
you just need a valid link to download any asset.For paperclip,this is how i download the asset(image/audio/video)
def download_video
#video = Video.find params[:id]
redirect_to #video..avatar.expiring_url(10)
end
I want to have all the errors appear on top of their respective areas.
I ran an if statement with any? on the first one but I know I am repeating myself and have to do it the Rails way.
Any help?
<%= form_for #movie, :html => {:class => "form-horizontal"} do |f| %>
<div class="control-group">
<% if #movie.errors[:title].any? %>
<div class="alert alert-error"><%= #movie.errors[:title].to_sentence %></div>
<% end %>
<%= f.label :title, :class => "control-label" %>
<div class="controls">
<%= f.text_field :title %>
</div>
</div>
<div class="control-group">
<div class="alert alert-error"><%= #movie.errors[:description].to_sentence %></div>
<%= f.label :description,:class => "control-label" %>
<div class="controls">
<%= f.text_area :description, :class => "span8", :rows => "10" %>
</div>
</div>
<div class="control-group">
<div class="alert alert-error"><%= #movie.errors[:rating].to_sentence %></div>
<%= f.label :rating, :class => "control-label" %>
<div class="controls">
<%= f.select :rating, Movie::RATINGS, prompt: "Pick one" %>
</div>
</div>
<div class="control-group">
<div class="alert alert-error"><%= #movie.errors[:total_gross].to_sentence %></div>
<%= f.label :total_gross, :class => "control-label" %>
<div class="controls">
<%= f.number_field :total_gross %>
</div>
</div>
<div class="control-group">
<div class="alert alert-error"><%= #movie.errors[:released_on].to_sentence %></div>
<%= f.label :released_on, :class => "control-label" %>
<div class="controls">
<%= f.date_select :released_on, :order => [:month, :day, :year], :prompt => { :month => 'Select month',:day => 'Select day', :year => 'Select year' }, :start_year => 1950 %>
</div>
</div>
<div class="control-group" >
<%= f.label :image_file_name, :class => "control-label" %>
<div class="controls">
<%= f.text_field :image_file_name %>
</div>
</div>
<div class="form-actions">
<%= f.submit :class => "btn btn-success btn-large" %> <%= link_to "Cancel", root_path, class: "btn btn-danger btn-large" %>
</div>
<% end %>
Here's a solution that will be more DRY and won't necessitate gems like simple_form.
Create a partial for your control group and replace the field name and form field helper with variables:
# File: _control_group.html.erb
<% show_errors = true if show_errors.nil? %>
<div class="control-group">
<% if #movie.errors[field_name].present? && show_errors %>
<div class="alert alert-error">
<%= #movie.errors[field_name].to_sentence %>
</div>
<% end %>
<%= label_tag field_name, :class => "control-label" %>
<div class="controls">
field_helper
</div>
</div>
Then replace these items in your form with a partial render and pass the appropriate code in through the parameters:
<%= form_for #movie, :html => {:class => "form-horizontal"} do |f| %>
<%= render "control_group", field_name: :title, field_helper: f.text_field(:title) %>
<%= render "control_group", field_name: :description, field_helper: f.text_area(:description, :class => "span8", :rows => "10") %>
<%= render "control_group", field_name: :rating, field_helper: f.select(:rating, Movie::RATINGS, prompt: "Pick one") %>
<%= render "control_group", field_name: :total_gross, field_helper: f.number_field(:total_gross) %>
<%= render "control_group", field_name: :released_on, field_helper: f.date_select(:released_on, :order => [:month, :day, :year], :prompt => { :month => 'Select month',:day => 'Select day', :year => 'Select year' }, :start_year => 1950) %>
<%= render "control_group", field_name: :image_file_name, field_helper: f.text_field(:image_file_name), show_errors: false %>
<div class="form-actions">
<%= f.submit :class => "btn btn-success btn-large" %> <%= link_to "Cancel", root_path, class: "btn btn-danger btn-large" %>
</div>
<% end %>
Ran into a similar problem.
Using simple_form worked for me. See an example here