ユーザーが持つ、荷物一覧で個々にチェックボックスを入れたらデータベースに自動入力させたいです
views/users/html/haml
.wrappers -# .user_name -# = @user.name .user_box - @baggages.each do |baggage| .user_box__field .user_box__label 追跡番号 .user_box__date = baggage.code .user_box__label 到着日時 .user_box__date = baggage.created_at.strftime("%Y年%m月%d日 %H時%M分") .user_box__link = link_to '詳細', baggage_path(baggage.id) .user_box__post - if current_user.admin? = form_with model: baggage, method: :patch do |f| -# = f.check_box :delivery_data -# = f.label :delivery_data = f.check_box :delivery_data, {cheked: baggage[:delivery_data]}#, true, false -# = f.submit 'SEND', class: "baggage__send" = paginate @baggages
users.controller.rb
class UsersController < ApplicationController def show # redirect_to root_path unless current_user || current_user.admin? @user = User.find(params[:id]) @baggages = Baggage.where(user_id: @user.id).order("created_at DESC").page(params[:page]).per(5) end def update baggage.update(delivery_data_params) respond_to do |format| format.json end end private def delivery_data_params params.require(:baggage).permit( :kind,:storage_period, :code, :user_id, :delivery_data ) # params.require(:baggage).permit(:delivery_data) end end
baggage.js
jQuery(document).ready(function() { $('input[name="baggage[delivery_data]"]').change(function() { Rails.fire($('#baggage_delivery_data').parent()[0], 'submit'); }); });
routes.rb
Rails.application.routes.draw do # get 'mypages/index' root 'pages#index' get 'pages/show' devise_for :users resources :baggages resources :users namespace :admin do resources :baggages do end end end
あなたの回答
tips
プレビュー