manage/productsコントローラのnewメソッドを実行した時、URLが
http://localhost:3000/manage/products/new.%23%3CProduct::ActiveRecord_Relation:0x007feee9cca940%3E
のように、「ActiveRecord_Relation」が含まれるURLが生成されます。
このメソッドを実行しても問題なくcreateされるのですが、このようなURLが生成される原因が何なのかわかりません。
環境
Rails 4.2.6
ルーティング
ruby
1#config/routes.rb 2 3namespace :manage do 4 resources :products do 5 member do 6 get 'enable' 7 get 'disable' 8 get 'requests' 9 end 10 end 11end
bundle exec rake routesで出力されるmanage/productsコントローラのnewメソッドの箇所は
new_manage_product GET /manage/products/new(.:format) manage/products#new
です。
productsコントローラのnewメソッドとビューのコードは以下です。
ruby
1 def new 2 p_params = { area_id: params[:area_id], building_name: params[:building_name], station: params[:station], address: params[:address], floor: params[:floor] } 3 @product = Product.new(p_params) 4 @product_images = [] 5 end
ruby
1<h2 class="head2">new</h2> 2 3<%= render 'form' %>
ruby
1manage/products/_form.html.erb 2 3<%= form_for([:manage,@product]) do |f| %> 4 <% if @product.errors.any? %> 5 <div class="alert-error"> 6 <p class="error-msg">エラーが発生しました</p> 7 <ul> 8 <% @product.errors.full_messages.each do |alert| %> 9 <li><%= alert %></li> 10 <% end %> 11 </ul> 12 </div> 13 <% end %> 14 <div class="input manage-product-create-form"> 15 <p class="row"><%= f.label :area_id, class: "label" %><%= f.select :area_id, @areas.map{ |t| [t.name, t.id] }, include_blank: true %></p> 16 <p class="row"><%= f.label :building_name, class: "label" %><%= f.text_field :building_name %></p> 17 <p class="row"><%= f.label :number, class: "label" %><%= f.text_field :number %></p> 18 <p class="row"><%= f.label :floor, class: "label" %><%= f.select :floor, Request::FLOOR, include_blank: true %></p> 19 <p class="row"><%= f.label :station, class: "label" %><%= f.text_field :station %></p> 20 <p class="row"><%= f.label :address, class: "label" %><%= f.text_field :address %></p> 21 <p class="row" id="js-selectFile"> 22 <%= f.label :zip, class: "label" %> 23 <%= f.file_field :zip, id: "js-upload" %> 24 <%= f.hidden_field :zip_cache, id: "js-upload-cache" %> 25 <button class="original-btn">ZIPファイルを選択</button> 26 <span class="icon">未選択</span> 27 </p> 28 <div class="sort-box-container sortable"> 29 <% (1..30).each do |num| %> 30 <div class="sort-box"> 31 <div id="<%= num %>" class="input-group"> 32 <%= f.file_field :"products_image#{num}", class: "uploadFile" %> 33 </div> 34 <input type="text" class="form-control" readonly=""> 35 <input type="hidden" id="result" name="result" /> 36 <div class="imagePreview item"> 37 </div> 38 </div> 39 <% end %> 40 </div> 41 </div> 42 <div class="actions"> 43 <%= button_tag type: 'submit', id: "submit", class: "btn-edit" do %> 44 <i class="fa fa-pencil" aria-hidden="true"></i> 作成 45 <% end %> 46 <%= link_to manage_products_path, class: "btn-back set-ml-10" do %> 47 <i class="fa fa-arrow-circle-left" aria-hidden="true"></i> 一覧に戻る 48 <% end %> 49 </div> 50<% end %>
何かご教示いただけることがありましたら、ご教示の方よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー