2013-04-05 22 views
0

未定義的方法'你好」爲Karlsgem :: KarlsGeming:類回報率 - 未定義的方法'你好「爲Karlsgem :: KarlsGeming:類

請大家幫忙,我只是希望它在視圖中顯示的字符串的不能似乎包裹我的頭圍繞?我在錯誤的文件中?

karlsgem.rb

require "karlsgem/version" 

module Karlsgem 
    class KarlsGeming 
     def hello 
      puts "Hello World" 
     end 

    end 
end 

index.html.erb

<% if notice %> 
<p id="notice" ><%= notice %></p> 
<% end %> 

<%= @kgem %> 

<h1>Your Drinks Catalog</h1> 
<% @products.each do |product| %> 
<div class="entry" > 
<%= image_tag(product.image_url) %> 
<h3><%= product.title %></h3> 
<%=sanitize product.description %> 
<div class="price_line" > 
<span class="price" >€<%= product.price %></span> 
<%= button_to 'Add to Cart' , line_items_path(:product_id => product) %> 
</div> 
</div> 
<% end %> 

store_controller.rb

require 'karlsgem' 

class StoreController < ApplicationController 
    def index 
@products = Product.all 
@cart = current_cart 

@kgem = Karlsgem::KarlsGeming.hello 

    end 
end 
+0

它只是調用從寶石的方法,不知道爲什麼即時得到錯誤 – megatron2000 2013-04-05 17:11:25

回答

0

你定義爲hello實例方法。爲了做到Karlsgem::KarlsGeming.hello你就必須將它定義爲一個類的方法:

require "karlsgem/version" 
module Karlsgem 
    class KarlsGeming 
    def self.hello 
     puts "Hello World" 
    end 
    end 
end 
相關問題