2016-03-25 17 views
0

Gem breadcrumbs_on_rails kullanmaya çalışıyorum.NoMethodError kullanırken breadcrumbs_on_rails gem

Aracım modelimin geçerli niteliğini, geçerli ekmek kırıntıları öğesinde kullanmak istiyorum. Bu nedenle, aynı bağlamda tanımlanan karşılık gelen yöntemi çağıran ve Öğe özniteliğini döndürülen bir Öğe Olarak Kırpma Öğesi olarak kullanıyorum değer (gem documentation uyarınca).

#vehicles_controller.rb 
    def show 
    @vehicle = Vehicle.find(params[:id]) 
    @user = User.find(params[:user_id]) 
    add_breadcrumb "home", :root_path 
    add_breadcrumb "user profile", :current_user 
    add_breadcrumb :set_vehicle_name, :user_vehicle_path 
    end 

    ... 

    private 

    #return vehicle name for breadcrumb 
    def set_vehicle_name 
     @vehicle.name 
    end 

Bence şu şekilde olmaktadır:

#vehicles/show.html..erb 
<ol class="breadcrumb"> 
    <%= render_breadcrumbs :separator => "/" %> 
</ol> 

Ben sunucuyu çalıştırın ve aşağıdaki hatayı alıyorum sayfasına eriştiğinizde:

NoMethodError in Vehicles#show 
undefined method `set_vehicle_name' for #<#<Class:0x007f40edd52958>:0x007f40f18fe790> 

Bu hatayı neyin sebep söyleyebilir ? teşekkürler

+0

'set_vehicle_name' özel yöntemdir yardımcı olabilir umuyoruz. 'Korunan' veya 'genel' yap. – archana

+0

bunu herkese açık hale getirme – davideghz

cevap

0

this gönderiminde belirtildiği gibi, özel yöntem tanımından sonra helper_method :set_vehicle_name eklemeye çalıştım.

The gem uses the context of an ActionView::Base (breadcrumbs.rb#L25) to evaluate any methods (breadcrumbs.rb#L50). It's complaining because you haven't made your method in your controller available to the view.

Use helper_method to make it available to your views and it will work.

o

İlgili konular