Skip to content

Instantly share code, notes, and snippets.

@gregory
Created March 12, 2012 10:05
Show Gist options
  • Select an option

  • Save gregory/2021014 to your computer and use it in GitHub Desktop.

Select an option

Save gregory/2021014 to your computer and use it in GitHub Desktop.
= f.inputs :name => :code_promo, :class => 'inputs foldable' do
= f.input :validity_start, :as => :datetime, :include_blank => false
= f.input :validity_end,:as => :datetime, :include_blank => false
class DeductionController < BaseController
before_filter :current_deduction
helper_method :current_deduction
def create
raise current_deduction.inspect
if current_deduction.save
redirect_to admin_deductions_url
else
flash[:error] = "Veuillez corriger les erreurs "
render :new
end
end
def current_deduction
args = params[:deduction].present? ? params[:deduction] : {:validity_start => DateTime.now, :validity_end => DateTime.now + 1.year}
@current_deduction= params[:id].present? ? Deduction.not_hidden.includes(:deduction_codes).find(params[:id]) : Deduction.new(args)
end
end
#<Deduction id: nil, validity_end: "2012-03-17 00:00:00", validity_start: "2012-03-12 00:00:00">
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"+YCcpyg=",
"deduction"=>{
"validity_start(3i)"=>"12",
"validity_start(2i)"=>"3",
"validity_start(1i)"=>"2012",
"validity_start(4i)"=>"10",
"validity_start(5i)"=>"12",
"validity_end(3i)"=>"17",
"validity_end(2i)"=>"6",
"validity_end(1i)"=>"2013",
"validity_end(4i)"=>"14",
"validity_end(5i)"=>"12"},
"commit"=>"Create"}
create_table "deductions", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment