【问题标题】:redmine plugin development NameErrorredmine 插件开发 NameError
【发布时间】:2012-12-28 18:37:18
【问题描述】:

我不是 Rails 开发人员。我是一名系统工程师,试图创建一个简单的 redmine 插件来显示备份文件夹的内容。基本上是 Dir.glob("/path/to/folder") 的输出。我可以在 irb 控制台中实现这一点。

我遵循官方 redmine 插件教程。我不需要任何模型,因为我不想存储任何数据库。这只是显示文件系统内容的视图。我创建了一个自动生成视图的控制器。我收到名称错误。粘贴我为相关文件制作的代码。请帮助我制作一个仅将文件夹内容输出到浏览器的 redmine 插件。另外,如何执行某些系统调用并在插件中显示输出?

插件名称:redmine_backups

控制器:backups_controller.rb 我根本没有碰过这个文件。

app/views/backups/index.html.erb

<h2>Backups#index</h2>

<table>
<ul>
<% @files = Dir.glob("/tmp/*") %>
<% @files.each do |f| %>
<%= f %>
<% end %>
</ul>
</table>

redmin_backups/init.rb

require 'redmine'

Redmine::Plugin.register :redmine_backups do
name 'Redmine Database Backups plugin'
author 'Author'
description 'This is a plugin for displaying database backups within Redmine'
version '0.0.1'
url 'http://example.com/path/to/plugin'
author_url 'http://example.com/about'

menu :application_menu, :backups, { controller => 'backups', :action => :index }, :caption => 'Backups', :last => 'true'
end

我得到的错误是 undefined local variable or method 'controller' for #&lt;Redmine::Plugin:0x7f28330ca2f8&gt;

【问题讨论】:

    标签: ruby-on-rails plugins redmine


    【解决方案1】:

    您需要在倒数第二行的控制器前面加一个冒号。它应该是menu :application_menu, :backups, { :controller =&gt; 'backups', :action =&gt; :index }, :caption =&gt; 'Backups', :last =&gt; 'true',这样 :controller 就是一个红宝石符号。

    【讨论】:

    • 非常感谢!那是一个错字。慢慢了解rails。新手有什么好的资源吗?
    • 如果你想真正深入到 Rails 中,Michael Hartl's Rails Tutorial Book 绝对很棒。 Rails for Zombies 也很棒。这是一个很大的框架,真正了解它肯定需要一些工作。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2013-06-07
    • 1970-01-01
    相关资源
    最近更新 更多