Ben raylara yeniyim. aşağıdaki gibi shop_products
indeksi için kontrolör tanımlanmışActionController :: UrlGenerationError ShopProfiles # index
shop_profile.rb
class ShopProfile < ActiveRecord::Base
has_and_belongs_to_many :users
has_one :shop_inventory_detail
end
shop_product.rb
class ShopProduct < ActiveRecord::Base
belongs_to :shop_profile
end
shop_products_controller.rb
class ShopProductsController < ApplicationController
def index
@shop_profile = ShopProfile.find(params[:shop_profile_id])
@products = @shop_profile.shop_products
end
end
shopprofiles içinde
index.html.erb hata olsun bu hat üzerinde
<%= link_to 'All Products', shop_profile_shop_products_path(@shop_profile) ,class: 'btn btn-primary' %>
o
ActionController::UrlGenerationError in ShopProfiles#index
Showing /home/mindfire/Desktop/project/training/Rails/grocery-shop/app/views/shop_profiles/index.html.erb where line #4 raised:
No route matches {:action=>"index", :controller=>"shop_products", :shop_profile_id=>nil} missing required keys: [:shop_profile_id]
yolları
shop_profile_shop_products GET /users/shop_profiles/:shop_profile_id/shop_products(.:format) shop_products#index
POST /users/shop_profiles/:shop_profile_id/shop_products(.:format) shop_products#create
new_shop_profile_shop_product GET /users/shop_profiles/:shop_profile_id/shop_products/new(.:format) shop_products#new
edit_shop_profile_shop_product GET /users/shop_profiles/:shop_profile_id/shop_products/:id/edit(.:format) shop_products#edit
shop_profile_shop_product GET /users/shop_profiles/:shop_profile_id/shop_products/:id(.:format) shop_products#show
PATCH /users/shop_profiles/:shop_profile_id/shop_products/:id(.:format) shop_products#update
PUT /users/shop_profiles/:shop_profile_id/shop_products/:id(.:format) shop_products#update
DELETE /users/shop_profiles/:shop_profile_id/shop_products/:id(.:format) shop_products#destroy
Ve geçmesi shop_profile_id
manuel olarak ben t istenilen sayfa. Yardımlarınız için şimdiden teşekkür ederiz.
shop_profiles_controller.rb
class ShopProfilesController < ApplicationController
before_action :authenticate_user!, except: :show
after_action :verify_authorized, only: :shop_index
def new
@shop = ShopProfile.new
end
def index
@shops = current_user.shop_profiles
end
def show
@shop_profile = ShopProfile.find_by(id: params[:id])
@items = @shop_profile.shop_products.group(:category_id).where(category_id: params[:category_id])
end
def create
@shop = ShopProfile.new(shop_params)
@shop.build_address(address_params_shopkeeper)
if current_user.shop_profiles << @shop
flash[:success] = 'Shop Details added'
redirect_to root_path
else
flash[:error] = 'Shop Details not added'
render 'new'
end
end
def edit
@shop = current_user.shop_profiles.find_by(id: params[:id])
end
def update
@shop = current_user.shop_profiles.find_by(id: params[:id])
if @shop.update_attributes(shop_params) and @shop.address.update_attributes(address_params_shopkeeper)
flash[:success] = 'Updated Successfully'
redirect_to shop_profiles_path
else
flash[:danger] = 'Shop Details not Updated'
render 'edit'
end
end
end
Ama shop_profiles_controller ile ilgisi yoktur düşünüyorum. Oradan shop_product dizin sayfasını arıyordum.
hata günlüğü
Started GET "https://stackoverflow.com/users/shop_profiles" for 127.0.0.1 at 2016-03-31 16:36:34 +0530
Processing by ShopProfilesController#index as HTML
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1
Rendered shop_profiles/index.html.erb within layouts/application (2.3ms)
Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.4ms)
ActionView::Template::Error (No route matches {:action=>"index", :controller=>"shop_products", :shop_profile_id=>nil} missing required keys: [:shop_profile_id]):
1: <div>
2: <%= link_to 'Add Shop' ,new_shop_profile_path, class: 'btn btn-primary' %>
3: <%= link_to 'Add New Product', new_product_path, class: 'btn btn-primary', method: :get %>
4: <%= link_to 'All Products', shop_profile_shop_products_path(@shop_profile) ,class: 'btn btn-primary' %>
5: </div>
6: <div>
7: <% if [email protected]? %>
app/views/shop_profiles/index.html.erb:4:in `_app_views_shop_profiles_index_html_erb___2474323268141556614_25251260'
Rendered /home/mindfire/.rvm/gems/[email protected]/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (9.0ms)............
'@ shop_profile''n'n'n'n suren n suren suren ,n Aren Aren ayn Ares 'n Aren oldu Aregundan emin misiniz? Shop_profile_shop_products_path (@ shop_profile.id)'? –
this 'shop_profile_shop_products_path (shop_profile_id: @ shop_profile.id) ' – illusionist
' ActionController :: UrlGenerationError'da ShopProfiles # index' - Hatanız, sorunun "ShopProfilesController" içinde olduğunu söylüyor. ShopProfilesController' kontrol cihazınızı gönderir misiniz? – dp7