小编w1n*_*1ng的帖子

模型中不能包含模块

我正在使用

Ruby version              1.8.7
Rails version             3.0.3
Run Code Online (Sandbox Code Playgroud)

我的rails应用程序的每个模型都有一个名为alive的方法:

  def alive
    where('deleter is null')  
  end   
Run Code Online (Sandbox Code Playgroud)

我不想在每个模型中复制此代码,因此我创建了一个/lib/life_control.rb

module LifeControl    
  def alive
    where('deleter is null')  
  end   

  def dead
    where('deleter is not null')  
  end    
end
Run Code Online (Sandbox Code Playgroud)

在我的模型中(例如client.rb)我写道:

class Client < ActiveRecord::Base
  include LifeControl   
end
Run Code Online (Sandbox Code Playgroud)

在我的config/enviroment.rb中我写了这一行:

require 'lib/life_control'
Run Code Online (Sandbox Code Playgroud)

但现在我得到一个no方法错误:

NoMethodError in
ClientsController#index

undefined method `alive' for
#<Class:0x10339e938>

app/controllers/clients_controller.rb:10:in
`index'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

ruby ruby-on-rails ruby-on-rails-3

12
推荐指数
2
解决办法
8913
查看次数

物质和MacOS MenuBar

我有一个扩展JFrame的Class MainWindow.在MainWindow我有一个JMenuBar.

我想在OSX上显示MenuBar(Apple符号旁边).这只适用,当我没有设置物质皮肤.是否可以使用Substance Skin并使用MacOS MenuBar?

我的代码:

//Set Menu for MacOS
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", name);

try {
    SwingUtilities.invokeAndWait(new Runnable() {  
        public void run() {
            SubstanceSkin skin = new GraphiteGlassSkin();
            SubstanceLookAndFeel.setSkin(skin); //WORKS WHEN I COMMENT THIS (WITHOUT SUBSTANCE SKIN)
            JFrame.setDefaultLookAndFeelDecorated(false);
            MainWindow mainWindow = new MainWindow(name);
            mainWindow.setVisible(true);
        }  
    });
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

java macos swing look-and-feel substance

5
推荐指数
2
解决办法
763
查看次数