小编luc*_*tte的帖子

Vim中的自动完成方法结构

有谁知道是否有办法在Vim中自动完成方法?对于Ruby中的示例,如果我输入:

def my_method
Run Code Online (Sandbox Code Playgroud)

并按Enter键,它将填充end并将光标移动到x所在的位置:

def my_method
  x
end
Run Code Online (Sandbox Code Playgroud)

ruby vim

3
推荐指数
1
解决办法
701
查看次数

如果键盘正在使用,如何在TimePicker中更改时间?

我有一个小部件,它是一个TimePicker,用于检索数据库中字段中保存的时间.

事情是,当用户更改窗口小部件中的时间值时,这不会保存在数据库中.

所以我遇到了setOnTimeChangedListener方法,它就像一个魅力,如果你只使用小部件中的加号和减号.如果您使用关键字,它不会捕获更改.

这是我的代码:

pickedTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

        public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
            System.out.println("What time is it? "
                    + String.valueOf(arg0.getCurrentHour()) + ":"
                    + String.valueOf(arg0.getCurrentMinute()));
        }

    });
Run Code Online (Sandbox Code Playgroud)

我也尝试过失败:

pickedTime.setOnFocusChangeListenerpickedTime.setOnKeyListener方法.

android timepicker

2
推荐指数
1
解决办法
5377
查看次数

Ruby on rails activerecord join - 从多个表中选择字段

楷模:

#StatusMessage model
class StatusMessage < ActiveRecord::Base
  belongs_to :users
  default_scope :order => "created_at DESC"
end


#User Model
class User < ActiveRecord::Base
  has_many :status_messages 
end
Run Code Online (Sandbox Code Playgroud)

在控制器中,我想连接这两个表并从两个表中获取字段.例如,我想要email来自Userstatus来自的领域StatusMessage.我用的时候:

@status = User.joins(:status_messages)
Run Code Online (Sandbox Code Playgroud)

要么

@status = User.includes(:status_messages)
Run Code Online (Sandbox Code Playgroud)

它只给我用户表数据.

我该如何实现这个要求?

ruby activerecord join ruby-on-rails

2
推荐指数
1
解决办法
1万
查看次数

Rails错误"jquery.js不在路径中......"

我正在尝试在我的Ubuntu系统上用rails 3.1编写的Q&A应用程序.运行服务器(rails服务器)后,在浏览器中输入localhost:3000 url,我收到以下错误:

/var/lib/gems/1.8/gems/jquery-rails-1.0.14/vendor/assets/javascripts/jquery.js isn't in paths:
(...."displays a list of paths including /$home/myapp/jquery-rails/ruby/1.9.1/gems/jquery-rails-1.0.14/vendor/assets/javascripts".....). 
Run Code Online (Sandbox Code Playgroud)

我做了bundle update,它在最后一个路径中安装了jquery.js和所有其他.js文件.但我仍然得到同样的错误.关于我在这里做错了什么的任何建议?

PS当我输入URL localhost:3000时,它实际上尝试打开URL:http:// localhost:3000/session/new.必须是一些应用程序特定的逻辑

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

2
推荐指数
1
解决办法
731
查看次数

在ruby中查找数组和活动记录变量之间的相同值

应该是一个简单的,可能有点复杂的标题.

我有一个包含记录的变量:

@record = Records.all
Run Code Online (Sandbox Code Playgroud)

和一个包含一些task_id的数组:

@array #has for e.g. [1,2,3]
Run Code Online (Sandbox Code Playgroud)

我想做什么检查@records中记录列表的task_id列,看它们是否包含数组中的任何数字.如果他们这样做,那么我希望将这些数字放入另一个数组中.

我知道这很简单,但我一直很困惑,因为我对ruby语法很新.

ruby activerecord ruby-on-rails

2
推荐指数
1
解决办法
119
查看次数

Rails有办法管理有序列表吗?这样每个项目都有一个位置,如果一个元素被删除,位置会自动更新?

鉴于以下内容:

ListItem(位置,标题)

1,hello
2,hello2
3,hello3
4,hello4
5,hello5
Run Code Online (Sandbox Code Playgroud)

如果第3项,3,hello3被删除,有没有办法让位置自动更新,即位置5现在是位置4?

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

2
推荐指数
1
解决办法
773
查看次数

VIM , y+ 和尾随字符

当我试图将 VIM 中选择的文本复制到系统剪贴板缓冲区时,它告诉我一个错误:

y+ 的结果

我首先选择在可视化模式文本,并键入:y+,错误弹出,不会工作:y +,以及

PS:这只是一个没有保存到磁盘的新文件,所以我不认为这是文件格式的问题,尽管谷歌上的很多人都是这么说的

vim

2
推荐指数
1
解决办法
2104
查看次数

使用自定义验证器时RSpec失败

我在rails 3.1项目中使用了这种验证.

validates_presence_of :sales_price
validates_presence_of :retail_price
validates_numericality_of :sales_price, :greater_than => 0,
                          :allow_blank => true
validates_numericality_of :retail_price, :greater_than => 0,
                          :allow_blank => true

validate :sales_price_less_than_retail

def sales_price_less_than_retail
  if sales_price >= retail_price
    errors.add(:sales_price, "must be less than retail price.")
  end
end
Run Code Online (Sandbox Code Playgroud)

我正在使用rspec测试模型.当我只使用rails标准验证助手时,一切都很好.但是当我编写自定义验证器(sales_price_less_than_retail)时,测试开始失败.

这是测试的代码:

it { should validate_presence_of :sales_price }
it { should validate_presence_of :retail_price }
it { should validate_numericality_of :sales_price }
it { should validate_numericality_of :retail_price }
Run Code Online (Sandbox Code Playgroud)

这是工厂:

Factory.define :offer_option do |f|
  f.sales_price          rand(21) + 10  # $10-$30
  f.retail_price         { |a| a.sales_price …
Run Code Online (Sandbox Code Playgroud)

ruby validation rspec ruby-on-rails

2
推荐指数
1
解决办法
1202
查看次数

如何在生产模式下使用rails 3.1建立一个完整的"hello world"站点?

我正在努力在生产模式下设置基于rails的网站.中间目标是建立一个非常简单的网站.我使用的是Rails 3.1.0,rake 0.9.2.2和Ruby 1.9.2.

这是我尝试过的,到目前为止结果不成功:

最初,确保未设置RAILS_ENV

rails new test_project

cd test_project

rails generate scaffold User name:string email:string

rake db:migrate

rails s
Run Code Online (Sandbox Code Playgroud)

浏览到localhost:3000或localhost:3000/users

事情看起来不错.

现在,尝试将其设置为生产:

export RAILS_ENV=production

rake db:migrate

rake assets:precompile

rails s
Run Code Online (Sandbox Code Playgroud)

浏览到localhost:3000

问题: Routing Error; No route matches [GET] "/"

杀死铁轨

在config/routes中,添加 root :to => 'users#index'

rails s
Run Code Online (Sandbox Code Playgroud)

现在可以浏览到localhost:3000和localhost:3000/users

但是,rails会产生以下错误:

Started GET "/assets/application-00960e5186894b532975562d59176a6a.css" for 127.0.0.1 at 2011-11-26 23:09:44 -0800

  ActionController::RoutingError (No route matches [GET] "/assets/application-00960e5186894b532975562d59176a6a.css"):

  Started GET "/assets/application-ae30e133eabbb10d9464189d3fb71e25.js" for 127.0.0.1 at 2011-11-26 23:09:44 -0800

  ActionController::RoutingError (No route matches [GET] …
Run Code Online (Sandbox Code Playgroud)

production ruby-on-rails mode

2
推荐指数
1
解决办法
478
查看次数

改变vim或vi如何解释文件

所以我使用vim(vi)在命令行上编辑.每当我在一个以.php,.pl,.cgi,.pm等结尾的文件中编码时,它就会与它的语言相匹配,并进行正确的语法突出显示.但是,我正在编写一些perl脚本,我需要一些扩展名为".lib"的单独文件.有没有办法让我将vim解释为.pl文件?现在它只是突出显示红色的一切,看起来很糟糕.

vi vim syntax-highlighting

2
推荐指数
1
解决办法
677
查看次数