单元继承在 Cells-3.7.0、rails 3.1.1 中不起作用
我在使用带有 Rails 3.1.1 的 cells-3.7.0 gem 中的继承时遇到问题。看起来像一个错误,但我不确定。我有一个侧边栏,其中有一堆按钮,这些按钮的显示或不显示取决于不同的参数。我正在尝试使用单元格从视图中取出一些逻辑。除了继承之外,工作正常。我为每个按钮都有一个单元格,如下所示:
class AddCompanyCell < Cell::Rails
def display
render
end
end
class CompanyJobsCell < Cell::Rails
def display(args)
@company = args[:company]
render
end
end
这些单元格的规格如下:
describe AddCompanyCell do
context "cell rendering" do
context "rendering display" do
subject { render_cell(:add_company, :display) }
it { should have_link("Add Company", href: "/companies/new") }
end
end
context "cell instance" do
subject { cell(:add_company) }
it { should respond_to(:display) }
end
end
所有规格均通过。
显然,我有很多像上面这样的课程。它们只有一个 display
方法,但参数数量可变。因此,我尝试为所有这些实现一个父类:
class GeneralCell < Cell::Rails
def display(args)
args.each do |k,v|
eval("@#{k} = v")
end
render
end
end
所有规范都通过 GeneralCell
。但是,当我尝试应用继承时,例如:
class AddCompanyCell < GeneralCell
end
调用 render_cell 时失败:
Failure/Error: subject { render_cell(:add_company, :display, opts: {}) }
AbstractController::ActionNotFound:
The action 'display' could not be found for AddCompanyCell
请注意,AddCompanyCell (should respond_to(:display)
) 的第二个测试通过了。诡异的。有什么想法吗?
I have a problem using inheritance in cells-3.7.0 gem with rails 3.1.1. Looks like a bug, but I'm not sure. I have a Sidebar with a bunch of buttons that are displayed or not depending on different parameters. I am trying to use Cells to take out some logic from views. Works fine, except for inheritance. I have a cell for every button, like this:
class AddCompanyCell < Cell::Rails
def display
render
end
end
class CompanyJobsCell < Cell::Rails
def display(args)
@company = args[:company]
render
end
end
Specs for these cells look like:
describe AddCompanyCell do
context "cell rendering" do
context "rendering display" do
subject { render_cell(:add_company, :display) }
it { should have_link("Add Company", href: "/companies/new") }
end
end
context "cell instance" do
subject { cell(:add_company) }
it { should respond_to(:display) }
end
end
All specs pass.
Obviously, I have many classes like ones above. They have only one display
method, but with the variable number of parameters. So, I tried to implement a parent class for all of those:
class GeneralCell < Cell::Rails
def display(args)
args.each do |k,v|
eval("@#{k} = v")
end
render
end
end
All specs pass for GeneralCell
. But when I try to apply inheritance, like:
class AddCompanyCell < GeneralCell
end
I get failure when call render_cell:
Failure/Error: subject { render_cell(:add_company, :display, opts: {}) }
AbstractController::ActionNotFound:
The action 'display' could not be found for AddCompanyCell
Please note, that second test for AddCompanyCell (should respond_to(:display)
) passes. Weird. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论