質問編集履歴
3
以前のエラーは消えましたが、createされないため
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -147,4 +147,113 @@ | |
| 147 147 | 
             
                  = f.hidden_field :user_id
         | 
| 148 148 |  | 
| 149 149 | 
             
                  = f.submit 'SEND', class: "baggage__send"
         | 
| 150 | 
            +
            ```
         | 
| 151 | 
            +
             | 
| 152 | 
            +
             | 
| 153 | 
            +
            全く同じ記述の管理者用baggagesコントローラーがあり
         | 
| 154 | 
            +
            ```
         | 
| 155 | 
            +
            class Admin::BaggagesController < ApplicationController
         | 
| 156 | 
            +
              before_action :if_not_admin
         | 
| 157 | 
            +
              before_action :set_baggage, only: [:edit, :update, :show, :destroy]
         | 
| 158 | 
            +
              # before_action :move_to_index,only: [:show]
         | 
| 159 | 
            +
              
         | 
| 160 | 
            +
              def index
         | 
| 161 | 
            +
                if current_user.admin?
         | 
| 162 | 
            +
                # @baggages = Baggage.search(params[:search])
         | 
| 163 | 
            +
                @search = User.ransack(params[:q]) #:qは入力したクエリのq
         | 
| 164 | 
            +
                @users = @search.result#検索した"結果"ユーザーのparams丸ごと
         | 
| 165 | 
            +
                
         | 
| 166 | 
            +
                # @baggages = Baggage.find(params[:user_id])
         | 
| 167 | 
            +
                
         | 
| 168 | 
            +
                end
         | 
| 169 | 
            +
              end
         | 
| 170 | 
            +
             | 
| 171 | 
            +
              def new
         | 
| 172 | 
            +
                if current_user.admin?
         | 
| 173 | 
            +
                  @baggage = Baggage.new(baggage_params)
         | 
| 174 | 
            +
                  
         | 
| 175 | 
            +
                end
         | 
| 176 | 
            +
              end
         | 
| 177 | 
            +
             | 
| 178 | 
            +
              def create
         | 
| 179 | 
            +
                # @baggage = current_user.baggages.build(baggage_params)
         | 
| 180 | 
            +
                # @baggage = Baggage.new.(user_id: @user.id)
         | 
| 181 | 
            +
                # binding.pry
         | 
| 182 | 
            +
                @baggage = Baggage.new(baggage_params)
         | 
| 183 | 
            +
                if @baggage.save
         | 
| 184 | 
            +
                  
         | 
| 185 | 
            +
                  redirect_to pages_show_path(@baggage)
         | 
| 186 | 
            +
                else
         | 
| 187 | 
            +
                  # render :new
         | 
| 188 | 
            +
                  render file: "admin/baggages/new."
         | 
| 189 | 
            +
                end
         | 
| 190 | 
            +
              end
         | 
| 191 | 
            +
             | 
| 192 | 
            +
              def edit
         | 
| 193 | 
            +
                # if current_user.admin?
         | 
| 194 | 
            +
                # end
         | 
| 195 | 
            +
              end
         | 
| 196 | 
            +
             | 
| 197 | 
            +
              def update
         | 
| 198 | 
            +
                if @baggage.update(baggage_params)
         | 
| 199 | 
            +
                  redirect_to pages_show_path(@baggage)
         | 
| 200 | 
            +
                else
         | 
| 201 | 
            +
                  render :edit
         | 
| 202 | 
            +
                end
         | 
| 203 | 
            +
              end
         | 
| 204 | 
            +
             | 
| 205 | 
            +
              def show
         | 
| 206 | 
            +
                # binding.pry
         | 
| 207 | 
            +
                # @baggage = Baggage.find_by(id: params[:id])
         | 
| 208 | 
            +
                # @user = User.find_by(id: @baggage.user_id)
         | 
| 209 | 
            +
              end
         | 
| 210 | 
            +
             | 
| 211 | 
            +
              def destroy
         | 
| 212 | 
            +
              end
         | 
| 213 | 
            +
             | 
| 214 | 
            +
             | 
| 215 | 
            +
             | 
| 216 | 
            +
              private
         | 
| 217 | 
            +
              
         | 
| 218 | 
            +
             | 
| 219 | 
            +
              def if_not_admin
         | 
| 220 | 
            +
                redirect_to root_path unless current_user.admin?#管理者ユーザー以外が特定のアクションを実行しようとした場合トップページにリダイレクトされる
         | 
| 221 | 
            +
              end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
              def set_baggage
         | 
| 224 | 
            +
                @baggage = Baggage.find(params[:id])#edit, show, destroy などのアクションで使用する変数をセットします。
         | 
| 225 | 
            +
                
         | 
| 226 | 
            +
              end
         | 
| 227 | 
            +
             | 
| 228 | 
            +
              def baggage_params
         | 
| 229 | 
            +
                params.permit(
         | 
| 230 | 
            +
                  :kind,:storage_period, :code, :user_id )#.merge(user_id: current_user.id)
         | 
| 231 | 
            +
              end
         | 
| 232 | 
            +
             | 
| 233 | 
            +
              # def move_to_index
         | 
| 234 | 
            +
              #   redirect_to action: :index unless user_signed_in? && current_user.id == @baggage.user_id
         | 
| 235 | 
            +
              # end
         | 
| 236 | 
            +
             | 
| 237 | 
            +
             | 
| 238 | 
            +
            end
         | 
| 239 | 
            +
            ```
         | 
| 240 | 
            +
            と、修正したら以前のエラーは出なくなったものの、createはされず、下記のターミナルをみても、原因が掴めません
         | 
| 241 | 
            +
             | 
| 242 | 
            +
             | 
| 243 | 
            +
             | 
| 244 | 
            +
            ```
         | 
| 245 | 
            +
            app/controllers/baggages_controller.rb:34:in `create'
         | 
| 246 | 
            +
            Started POST "/baggages" for ::1 at 2020-10-27 08:18:42 +0900
         | 
| 247 | 
            +
            Processing by BaggagesController#create as JS
         | 
| 248 | 
            +
              Parameters: {"utf8"=>"✓", "authenticity_token"=>"r1DJfXsonsAr8fJOdEzLr7uyluXFz1uBTzK/4P++LNRUVBd8jgfp3ZNKbSlAe/I4ausFGKubcmtXmkuVhoHNfw==", "baggage"=>{"kind"=>"チルド", "storage_period"=>"7", "code"=>"111111111111", "user_id"=>"1"}, "commit"=>"SEND"}
         | 
| 249 | 
            +
            Unpermitted parameters: :utf8, :authenticity_token, :baggage, :commit
         | 
| 250 | 
            +
               (0.2ms)  BEGIN
         | 
| 251 | 
            +
              ↳ app/controllers/baggages_controller.rb:29
         | 
| 252 | 
            +
               (0.2ms)  ROLLBACK
         | 
| 253 | 
            +
              ↳ app/controllers/baggages_controller.rb:29
         | 
| 254 | 
            +
              Rendering baggages/new.html.haml within layouts/application
         | 
| 255 | 
            +
              Rendered baggages/new.html.haml within layouts/application (8.1ms)
         | 
| 256 | 
            +
              User Load (0.5ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
         | 
| 257 | 
            +
              ↳ app/views/layouts/application.html.haml:12
         | 
| 258 | 
            +
            Completed 200 OK in 219ms (Views: 173.9ms | ActiveRecord: 21.2ms)
         | 
| 150 259 | 
             
            ```
         | 
2
エラーで無いされているファイルです
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -117,4 +117,34 @@ | |
| 117 117 |  | 
| 118 118 | 
             
            end
         | 
| 119 119 | 
             
            ```
         | 
| 120 | 
            +
             | 
| 120 | 
            -
            リダイレクト先をroot_pathにしてみましたが変化ありません
         | 
| 121 | 
            +
            リダイレクト先をroot_pathにしてみましたが変化ありません
         | 
| 122 | 
            +
             | 
| 123 | 
            +
             | 
| 124 | 
            +
            エラーで無いと言われていたファイルです
         | 
| 125 | 
            +
            **app/views/admin/baggages/new.html.haml
         | 
| 126 | 
            +
            ```
         | 
| 127 | 
            +
            .wrapper
         | 
| 128 | 
            +
             | 
| 129 | 
            +
              .disply
         | 
| 130 | 
            +
                = form_with model: @baggage do |f|
         | 
| 131 | 
            +
                
         | 
| 132 | 
            +
                  .baggage
         | 
| 133 | 
            +
                    .baggage__box
         | 
| 134 | 
            +
                      %span
         | 
| 135 | 
            +
                        荷物の種類
         | 
| 136 | 
            +
                        = f.select :kind, [["なまもの", "なまもの"], ["チルド", "チルド"], ["冷凍", "冷凍"], ["その他", "その他"]], include_blank: "選択して下さい"
         | 
| 137 | 
            +
                    .baggage__box
         | 
| 138 | 
            +
                      %span
         | 
| 139 | 
            +
                        保管期限
         | 
| 140 | 
            +
                        = f.text_field :storage_period, class: "baggage_text" , placeholder: '例)7'
         | 
| 141 | 
            +
                        %span 日
         | 
| 142 | 
            +
                    .baggage__box
         | 
| 143 | 
            +
                      %span
         | 
| 144 | 
            +
                        追跡番号
         | 
| 145 | 
            +
                        = f.text_field :code, class: "baggage_text", placeholder: '123456789012'
         | 
| 146 | 
            +
                  -# = f.hidden_field :user_id , :value => "#{user_session}"
         | 
| 147 | 
            +
                  = f.hidden_field :user_id
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                  = f.submit 'SEND', class: "baggage__send"
         | 
| 150 | 
            +
            ```
         | 
1
行ってみたことを追記しました
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -116,4 +116,5 @@ | |
| 116 116 |  | 
| 117 117 |  | 
| 118 118 | 
             
            end
         | 
| 119 | 
            -
            ```
         | 
| 119 | 
            +
            ```
         | 
| 120 | 
            +
            リダイレクト先をroot_pathにしてみましたが変化ありません
         | 
