現在、RailsのGemのransackにて、検索フォームを作成しています。
再検索をした際にdatepicker内に変数が渡ってこない状態です。
実現したいこと
再描画した際に、datepicker内にunixtimeを変換しstring型の文字列表記を行いたい。
下記のようにpryで止めた際に@qの中身であるvaluesの取り出し方がわかりません。
わかる方がいらっしゃいましたら、ご教授ください。
原因
原因は、dbにはunixtimeで保存しているため、検索をかける際に、下記のようにunixtimeに変換しており、再描画された際に、@qにunixtimeが入っているためだと認識しています。
pryでとめた際の中身
[1] pry(#<JobSchedulesController>)> @q => Ransack::Search<class: JobSchedule, base: Grouping <conditions: [Condition <attributes: ["start_time"], predicate: gteq, values: [1519988640]>], combinator: and>>
コントローラー
def index if params[:q].present? if params[:q]["start_time_gteq"].present? params[:q]["start_time_gteq"] = Time.parse(params[:q]["start_time_gteq"]).to_i end if params[:q]["end_time_lteq"].present? params[:q]["end_time_lteq"] = Time.parse(params[:q]["end_time_lteq"]).to_i end end binding.pry @q = JobSchedule.ransack(params[:q]) @jobs = Job.mycontent(current_user) @schedules = ( params[:q].nil? ) ? JobSchedule.mycontent(current_user).order(start_time: 'desc').page(params[:page]).per(15) : @q.result.ransack(mycontent: current_user).result.page(params[:page]).per(15) end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。