Ruby on Rails 3中,如何定义或引入未定义的局部变量或方法`render`?

2026-04-11 16:581阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计350个文字,预计阅读时间需要2分钟。

Ruby on Rails 3中,如何定义或引入未定义的局部变量或方法`render`?

我的rspec代码中出现了以下错误:+undefined local variable or method `render'。这是我的代码片段:

rubyrequire 'spec_helper'describe messages/show..erb do it displays the text attribute of the message do render rendered.should contain text attribute endend

错误提示表明`render`方法未定义。请确保在测试中正确调用`render`方法,或者如果你不需要手动调用,可以移除`render`行。以下是修改后的代码:

rubyrequire 'spec_helper'describe messages/show..erb do it displays the text attribute of the message do rendered.should contain text attribute endend

我的rspec代码中出现以下错误

undefined local variable or method `render'

这是我的代码:

Ruby on Rails 3中,如何定义或引入未定义的局部变量或方法`render`?

require 'spec_helper' describe "messages/show.html.erb" do it "displays the text attribute of the message" do render rendered.should contain("Hello world!") end end

这来自书:RSpec书
下面是我添加到Gemfile的内容.

group :development , :test do gem "rspec-rails", ">= 2.0.0" gem "webrat", ">= 0.7.2" end

我没有将文件show.html.erb添加到views / messages中,但我应该收到另一个错误,而不是这个

奇怪的是,这在我的机器上工作了一段时间.我删除了项目并创建了另一个项目,现在它不起作用

我在编辑gemfile后发出了这些命令

bundle install script/rails generate rspec:install rake db:migrate 对我来说,答案是改变

describe "messages/show.html.erb" do

describe "messages/show.html.erb", type: :view do

标签:局部变量

本文共计350个文字,预计阅读时间需要2分钟。

Ruby on Rails 3中,如何定义或引入未定义的局部变量或方法`render`?

我的rspec代码中出现了以下错误:+undefined local variable or method `render'。这是我的代码片段:

rubyrequire 'spec_helper'describe messages/show..erb do it displays the text attribute of the message do render rendered.should contain text attribute endend

错误提示表明`render`方法未定义。请确保在测试中正确调用`render`方法,或者如果你不需要手动调用,可以移除`render`行。以下是修改后的代码:

rubyrequire 'spec_helper'describe messages/show..erb do it displays the text attribute of the message do rendered.should contain text attribute endend

我的rspec代码中出现以下错误

undefined local variable or method `render'

这是我的代码:

Ruby on Rails 3中,如何定义或引入未定义的局部变量或方法`render`?

require 'spec_helper' describe "messages/show.html.erb" do it "displays the text attribute of the message" do render rendered.should contain("Hello world!") end end

这来自书:RSpec书
下面是我添加到Gemfile的内容.

group :development , :test do gem "rspec-rails", ">= 2.0.0" gem "webrat", ">= 0.7.2" end

我没有将文件show.html.erb添加到views / messages中,但我应该收到另一个错误,而不是这个

奇怪的是,这在我的机器上工作了一段时间.我删除了项目并创建了另一个项目,现在它不起作用

我在编辑gemfile后发出了这些命令

bundle install script/rails generate rspec:install rake db:migrate 对我来说,答案是改变

describe "messages/show.html.erb" do

describe "messages/show.html.erb", type: :view do

标签:局部变量