NoMethodError dans Rails, malgré la définition Méthode
I de Michael Hartl terminé avec succès Tutoriel Rails, et je travaille maintenant sur mon premier projet de développement web plus indépendant. J'ai lu autre NoMethodError Q & A sur StackOverflow, mais jusqu'ici rien n'aide.
Je réutilise un concept Hartl couvert, en définissant spécifiquement un assistant client appelé full_title
. J'ai mis le code follwoing dans /app/helpers/application_helper.rb
:
module ApplicationHelper
def full_title(page_title)
base_title = 'BaseTitle Text'
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
end
Puis, en app/views/layouts/application.html.erb
, j'ai mis ce code:
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
Avec ces tests spec/requests/static_pages_spec.rb
, je reçois un NoMethodError/undefined method
. Je ne suis pas tout à fait sûr pourquoi il n'y a pas de méthode étant reconnue ici.
it "should have the right links on the layout" do
visit root_path
click_link "About"
page.should have_selector 'title', text: full_title('About')
click_link "Contact"
page.should have_selector 'title', text: full_title('Contact')
Fyi J'utilise Capybara 1.1.2, au cas où cela serait important. Toute aide grandement appréciée.
Quelle erreur obtenez-vous exactement? –
'1) La page d'accueil de StaticPages devrait avoir les bons liens sur la mise en page Échec/Erreur: page.avoir has_selector 'title', texte: full_title ('About') NoMethodError: méthode non définie' full_title 'pour ' # ./spec/requests/static_pages_spec.rb:19:in 'bloc (3 niveaux) dans '' ' –