2016-04-11 24 views
0

我正在開發一個使用browser gem的Facebook爬蟲的預覽。問題在於渲染點。我不知道如何設置控制器中的respond_to模塊。目前,我有以下幾種:Facebook的爬行器呈現問題 - Ruby On Rails - 瀏覽器寶石

def show_preview 
@question = to_array(@question) 
question_package = formatting_questoins(@question,params[:id].to_i) 
@searched_question = question_package.first 

    respond_with do |format| 
    format.html { render 'show_preview' } 
    end 
end 

它不渲染任何東西。我嘗試過

respond_with do |format| 
    format.html { render 'show_preview' } 
    format.json 
    end 

但它也沒有渲染任何東西。任何幫助將升值

回答

1

Rails根據約定知道每個控制器操作使用哪個視圖。您的控制器MyController的動作show_preview將使用視圖views/my_controller/show_preview.html.erb

您不需要使用respond_withrender

所以,你的控制器動作變爲:

def show_preview 
    @question = to_array(@question) 
    question_package = formatting_questoins(@question,params[:id].to_i) 
    @searched_question = question_package.first 
end 

而且你的觀點views/my_controller/show_preview.html.erb現在可以以呈現的東西用@question@searched_question

文檔:http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action