2014-09-09 3 views
0

첫 번째 레일 웹 사이트를 작성 중이며 문제가 발생했습니다. "wikiquote"보석 (http://hemanth.github.io/wikiquote-gem/)을 사용하여 환영 페이지에 "오늘의 견적"을 보여주고 싶습니다. 나는 그것을 아래의 코드에 넣고 작동 할 것이라고 생각했지만 오해했다. 브라우저는 오류가 없다고 말하지 않지만 아무것도 표시하지 않습니다. 이견있는 사람? 나는이 일을 완전히 잘못하고 있니? <h3> <%= @qod.to_s %></h3>Rails로 고민 Wikiquote gem?

답변

1

welcome/index.html.erb에서 welcome_controller.rb

class WelcomeController < ApplicationController 

    def index 
    end  

    def get_qod 
    @qod = WikiQuote.get 
    end 
end 

에서

. 당신은 잘못하고있다.

인덱스에 @qod를 사용할 수있게하려면 index 안에 실행해야합니다.

class WelcomeController < ApplicationController 

    before_action :get_quote, only: [:index] 

    def index  
    end 

    private 
    def get_quote 
     @qod = WikiQuote.get 
    end 

end 
:

class WelcomeController < ApplicationController 

    def index 
    @qod = WikiQuote.get 
    end  

end 

또는 당신이 방법을 아웃소싱 할 수 있습니다