Closed CarbazochromeT closed 11 months ago
drugs_controller
class DrugsController < ApplicationController skip_before_action :require_login before_action :set_drug,only: [:show, :edit, :update, :destroy] def index @q = Drug.ransack(params[:q]) @drugs = @q.result(distinct: true).includes(:symptoms, :ingredients).page(params[:page]).per(10) end def show @drug = Drug.find(params[:id]) end def likes @q = current_user.like_drugs.ransack(params[:q]) @like_drugs = current_user.like_drugs.includes(:user).order(created_at: :desc) end private def set_drug @drug = Drug.find(params[:id]) end def drug_params params.require(:drugs).permit(:id, :drug, :name, :effect_text, :usage, :document_url, {formulation: []}, :division, :taxation, { symptom_ids: [] }, { ingredient_ids: [] }, :drive,:tobacco, :alcohol, :maker_names) end def search_params params[:q]&.permit(:id, :drug, :name, :effect_text, :usage, :document_url, {formulation: []}, :division, :taxation, { symptom_ids: [] }, { ingredient_ids: [] }, :drive,:tobacco, :alcohol, :maker_names) end end
_search.html.erb
<dl> <%= search_form_for @q, class: 'drug-search' do |f| %> <dt>成分名で検索</dt> <dd> <ul class= "search-list"> <li> <div class = "search-textarea"> <%= f.text_field :ingredients_name_cont_any, placeholder: '成分名で検索' %> </div> </li> </ul> </dd> <dt>商品名で検索</dt> <dd> <ul class= "search-list"> <li> <div class = "search-textarea"> <%= f.text_field :name_cont_any, placeholder: '商品名で検索' %> </li> </ul> </dd> <dt>どんな症状がありますか?</dt> <dd> <ul class= "search-list"> <%= f.collection_check_boxes :symptoms_name_in, Symptom.all , :id, :name, { multiple: true } do |b| %> <li> <label class="CheckboxInput"> <%= b.check_box(class: "CheckboxInput-Input") %> <span class="CheckboxInput-DummyInput"></span> <%= b.label(class: "CheckboxInput-LabelText") %> </label> </li> <% end %> </ul> </dd> <dt>剤型にこだわりはありますか?</dt> <dd> <ul class= "search-list"> <%= f.collection_check_boxes :formulation_eq_any, Drug.formulation.values.map { |v| [v.text, v.value] }.to_h, :last, :first do |b| %> <li> <label class="CheckboxInput"> <%= b.check_box(class: "CheckboxInput-Input") %> <span class="CheckboxInput-DummyInput"></span> <%= b.label(class: "CheckboxInput-LabelText") %> </label> </li> <% end %> </ul> </dd> <dt>車の運転はしますか?</dt> <dd> <ul class= "search-list"> <li> <div class="yesno"> <%= f.radio_button :ingredients_drive_eq, false, id:'drive_ok' %> <%= f.label :drive_true ,"はい", for: 'drive_ok', class:"switch-on" %> <%= f.radio_button :ingredients_drive_eq, true, id:'drive_ng', checked: true %> <%= f.label :drive_false ,"いいえ",for: 'drive_ng', class:"switch-off" %> </div> </li> </ul> </dd> <p style="clear:both"></p> <dt>タバコは吸いますか?</dt> <dd> <ul class= "search-list"> <li> <div class="yesno"> <%= f.radio_button :ingredients_tobacco_eq, false, id:'tobacco_ok' %> <%= f.label :tobacco_true ,"はい", for: 'tobacco_ok', class:"switch-on" %> <%= f.radio_button :ingredients_tobacco_eq, true, id:'tobacco_ng', checked: true %> <%= f.label :tobacco_false ,"いいえ",for: 'tobacco_ng', class:"switch-off" %> </div> </li> </ul> </dd> <p style="clear:both"></p> <dt>お酒は飲みますか?</dt> <dd> <ul class= "search-list"> <li> <div class="yesno"> <%= f.radio_button :ingredients_alcohol_eq, false, id:'alcohol_ok' %> <%= f.label :alcohol_true ,"はい", for: 'alcohol_ok', class:"switch-on" %> <%= f.radio_button :ingredients_alcohol_eq, true, id:'alcohol_ng', checked: true %> <%= f.label :alcohol_false ,"いいえ",for: 'alcohol_ng', class:"switch-off" %> </div> </li> </ul> </dd> <%= f.submit '検索', class: 'btn btnmint' do %> 検索ページに進む <% end %> </dl> <% end %>
drugs_controller
_search.html.erb