ruby on rails - I can't save two datetimes at the same time -


i'm trying submit form , have of data save database, 1 column not saved. have form set start_at datetime , and end_at datetime. when click create button appears both pieces of data being sent, 1 being saved database. @ first neither save, , don't know i've done 1 save.

i'm using rails 4.2.5.1, ruby 2.3, postgres 9.3, simple_form , bootstrap3-datetimepicker.

below code related issue, if able figure out i'm doing wrong i'd appreciate help.

_form.html.erb

<div class="form-group">     <%= simple_form_for shallow_args(current_user, @image) |f| %>     <%= render 'shared/error_messages', object: f.object %>     <%= f.label            :file %><br>     <%= f.attachment_field :file, direct: true %>      <div class="row">         <%= f.collection_check_boxes :category_ids, category.all, :id, :name |cb| %>         <% cb.label(class: "checkbox-inline input_checkbox") {cb.check_box(class: "checkbox") + cb.text}%>         <% end %>     </div>     <div class="container">         <div class="row">             <div class="col-sm-4">                 <div class="form-group">                     <%= label_tag :start_at, 'starttime' %>                     <div class="input-group date" id="datetimepicker">                         <%= f.text_field :start_at, class: 'form-control' %>                         <span class="input-group-addon">                             <span class="glyphicon glyphicon-calendar"></span>                         </span>                     </div>                 </div>             </div>             <div class="col-sm-4">                 <div class="form-group">                     <%= label_tag :end_at, 'end of image run' %>                     <div class="input-group date" id="datetimepicker1">                         <%= f.text_field :end_at, class: 'form-control' %>                         <span class="input-group-addon">                             <span class="glyphicon glyphicon-calendar"></span>                         </span>                     </div>                 </div>             </div>         </div>     </div>     <div class="actions">         <%= f.submit %>     </div>     <% end %> </div> 

assets/images.coffee

$(document).on "turbolinks:load", -> $('#datetimepicker').datetimepicker() $('#datetimepicker1').datetimepicker() 

images_controller.rb

# /images/new def new     @image = current_user.images.build end # post /images # post /images.json def create     @image = current_user.images.build(image_params)     respond_to |format|         if @image.save             format.html { redirect_to @image, notice: 'image created.' }             format.json { render :show, status: :created, location: @image }         else             format.html { render :new }             format.json { render json: @image.errors, status: :unprocessable_entity }         end     end end  def image_params     params.require(:image).permit(:file, :start_at, :end_at, category_ids: []) end 

parameters being passed copied server output:

    started post "/users/1/images" 127.0.0.1 @ 2016-07-15 14:46:59 -0400 processing imagescontroller#create html   parameters: {"utf8"=>"✓", "authenticity_token"=>"87o2h62exrltj084/ydt5n7pzjq+7ezh2xpk0e14vwtzya/gb9p6ydexfgydonfzxsdbknnx7vexk/80y+7n9w==", "image"=>{"file"=>"{\"id\":\"c4b7b6c51dd3b083e359e4fa2ba9da2023bef8597c1175a2f2f235c31018\",\"filename\":\"c8f98ef4b2acc1754bab905ee8d61afe.jpg\",\"content_type\":\"image/jpeg\",\"size\":33018}", "category_ids"=>["2", "5", ""], "start_at"=>"07/23/2016 2:46 pm", "end_at"=>"10/08/2016 7:46 pm"}, "commit"=>"create image", "user_id"=>"1"}   user load (0.3ms)  select  "users".* "users" "users"."id" = $1 limit 1  [["id", 1]]   category load (0.6ms)  select "categories".* "categories" "categories"."id" in (2, 5)    (0.2ms)  begin   category exists (0.4ms)  select  1 one "categories" ("categories"."name" = 'funny' , "categories"."id" != 2) limit 1   category exists (0.3ms)  select  1 one "categories" ("categories"."name" = 'cool stuff' , "categories"."id" != 5) limit 1   sql (0.6ms)  insert "images" ("file_id", "end_at", "user_id", "width", "height", "created_at", "updated_at") values ($1, $2, $3, $4, $5, $6, $7) returning "id"  [["file_id", "117118"], ["end_at", "2016-08-10 19:46:00.000000"], ["user_id", 1], ["width", "564"], ["height", "564"], ["created_at", "2016-07-15 18:46:59.157176"], ["updated_at", "2016-07-15 18:46:59.157176"]] 

what saved in database

   2.3.0 :001 > = image.last   image load (0.6ms)  select  "images".* "images"  order "images"."id" desc limit 1  => #<image id: 2, created_at: "2016-07-15 18:46:59", updated_at: "2016-07-15 18:46:59", user_id: 1, file_id: "117118", height: "564", width: "564", start_at: nil, end_at: "2016-08-10 19:46:00">  2.3.0 :002 >  

edit, requested images model:

image.rb

class image < activerecord::base   belongs_to :user    has_many   :gallery_images, dependent: :destroy   has_many   :galleries, through: :gallery_images    has_many   :categories, through: :category_images   has_many   :category_images    attachment   :file, type: :image   validates    :file, presence: true    before_save  :set_dimensions, if: :file_id_changed?    def set_dimensions     fileio = file.to_io     mm = if fileio.is_a?(stringio)            minimagick::image.read(fileio.read)          else            minimagick::image.read(file)          end      self.width  = mm.width     self.height = mm.height   end end 


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -