・form_forのパスでつまずいてます。
エラーが以下のように出て、詰まっております!ご教授お願い致します!!
/Users/app/views/products/edit.html.erb:9: syntax error, unexpected =>, expecting keyword_end ...for([@item,@product]), :html => { :multipart => true } do |f... ... ^ /Users/app/views/products/edit.html.erb:9: syntax error, unexpected keyword_do_block, expecting keyword_end ...ml => { :multipart => true } do |f| @output_buffer.safe_appe... ... ^ /Users/app/views/products/edit.html.erb:284: syntax error, unexpected keyword_ensure, expecting end-of-input
routes.rb
ruby
1resources :items do 2 resources :products, only: [:create, :edit, :update, :show] 3end
products_controller.erb
ruby
1class ProductsController < ApplicationController 2 def index 3 @products = current_user.products 4 end 5 6 def create 7 if user_signed_in? 8 @item = Item.find(params[:item_id]) 9 if @item.user.products.create(product_params) 10 redirect_back fallback_location: root_path, notice: "送信できました" 11 else 12 redirect_back fallback_location: root_path, notice: "送信できませんでした" 13 end 14 else 15 redirect_back fallback_location: root_path, notice: "ログインが必要です" 16 end 17 end 18 19 def edit 20 @item = Item.find(params[:item_id]) 21 @product = Product.find(params[:id]) 22 end 23 24 def update 25 @product = Product.find(params[:product_id]) 26 27 if @product.update(product_params) 28 redirect_back fallback_location: root_path, notice: "更新しました" 29 end 30 end 31 32 private 33 def product_params 34 params.require(:product).permit(:title, :description, :price, :cost, :item_id) 35 end 36 37end
edit.html.erb
ruby
1<%= form_for([@item,@product]), :html => { :multipart => true } do |f| %> 2. 3. 4. 5<% end %>
form_forのパスがいまいち理解できてないので、このようにエラーがでると分かっているのですが、改善方法が分かりません。
ご教授よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/12 05:29