我試圖添加一個新的類到我的標題模板的一部分,如果應用程序正在移動設備上查看,我得到這個錯誤從耙子(但它完美地工作在本地主機):rspec未定義的方法`mobile_device?'對於#<#類
失敗/錯誤:render:template =>「/layouts/_header.html.erb」 ActionView :: Template :: Error: 未定義的方法`mobile_device?'爲#<#:0x007fbbddbd0b50>
這是我的頭模板引起問題的行:
./app/views/layouts/_header.html.erb
<div class="<%= 'flexslider-mobile' if mobile_device? && !current_page?('/') %>">
<some html>
</div>
而且這是我在我的測試中呈現模板時卡住的線:
./spec/views/layouts/application_spec
require 'spec_helper'
describe 'header' do
before(:each) do
render :template => "/layouts/_header.html.erb"
end
./app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protected
def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile|webOS/
end
end
helper_method :mobile_device?
end
我新的軌道,並RSPEC,所以我敢肯定這件事情很明顯,我只是不知道.. 。謝謝你的幫助!
你試過方法mobile_device嗎?放棄保護? – 2014-09-26 21:43:00
試圖將其移出保護區域,這沒有什麼區別。不清楚你的意思是「method mobile_device?」你可以解釋嗎?謝謝 – COS 2014-09-27 11:34:14
我只是想移動mobile_device?出於保護..這就是它 – 2014-09-27 17:39:22