Rails 形式参数不能是实例变量? [英] Rails formal argument cannot be an instance variable?

查看:61
本文介绍了Rails 形式参数不能是实例变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 rails 错误,我不知道去哪里解决它.在products#show"我得到这个

I have a rails error and I don't know where to look to solve it. On a "products#show" I get this

SyntaxError at /products/63  formal argument cannot be an instance variable

我评论了控制器和视图中的所有内容

I commented everything out of the controller and the view

def show
  # @product = Product.find(params[:id])
end

我的错误 gem 将我指向 activesupport (3.2.13) lib/active_support/dependencies.rb

My error gem points me to activesupport (3.2.13) lib/active_support/dependencies.rb

  newly_defined_paths = new_constants_in(*parent_paths) do
    result = Kernel.load path     #this is the line with the error
  end

有什么想法吗?谢谢.

推荐答案

当您的块参数名称无效时,通常会出现此错误.

This error usually comes up when you have an invalid block parameter name.

例如 @products.each 做 |@product|...@products.each do |Product|... 都应该成为 @products.each do |product|.

For example @products.each do |@product| ... or @products.each do |Product|... should both be @products.each do |product|.

检查你的 products/show 视图文件,确保你的块参数都是小写的,没有 @ 符号.

Check your products/show view file and make sure your block parameters are all lower case words without the @ symbol.

这也可能在某个地方的方法定义中 (def my_method(@var)...)

It's also possible this is in a method definition somewhere (def my_method(@var)...)

这篇关于Rails 形式参数不能是实例变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆