小编Cur*_*urt的帖子

如何从Rails中的查询中排除一组id(使用ActiveRecord)?

我想执行一个ActiveRecord查询,该查询返回除具有某些id的记录之外的所有记录.我想要排除的ID存储在一个数组中.所以:

ids_to_exclude = [1,2,3]
array_without_excluded_ids = Item. ???
Run Code Online (Sandbox Code Playgroud)

我不知道如何完成第二行.

背景:我已经尝试过的:

我不确定背景是否必要,但我已经尝试过.find和.where的各种组合.例如:

array_without_excluded_ids = Item.find(:all, :conditions => { "id not IN (?)", ids_to_exclude })
array_without_excluded_ids = Item.where( "items.id not IN ?", ids_to_exclude)
Run Code Online (Sandbox Code Playgroud)

这些失败了. 这个提示可能在正确的轨道上,但我没有成功地适应它.任何帮助将不胜感激.

activerecord arel active-relation ruby-on-rails-3

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

Git-flow失败,"致命:没有标记消息?/标记失败.请再次运行完成重试"

我正在使用git-flow来管理项目.发出时我收到以下消息git flow release finish foo:

fatal: no tag message? 
Tagging failed. Please run finish again to retry. 
Run Code Online (Sandbox Code Playgroud)

以下是使用全新的git存储库和单个文件重现的一系列步骤:

touch test.txt 
git init 
git add . 
git commit -m "Initial commit" 
git flow init 
[defaults accepted] 
git flow release start 1.0 
echo "Line 1" >> test.txt 
git add . 
git commit -am "Line added" 
git flow release finish '1.0' 
Run Code Online (Sandbox Code Playgroud)

此时,会弹出上面的错误消息,并调用Vim来添加标记.当我添加标签并保存时,我最终在主分支上,发布/ 1.0分支仍然存在.出了什么问题?Git流版本是0.4.1.

谢谢.

git git-flow

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

在Heroku上使用Compass:/ tmp远程和本地使用样式表

我目前正在使用Heroku知识库推荐的配置使用Compass和Heroku .Heroku有一个只读文件系统,因此编译好的样式表需要存储在/ tmp中.这在Heroku上工作得很好; 但是,Rails希望在/ public/stylesheets中找到样式表(通过调用时= stylesheet_link_tag 'screen.css', :media => 'screen, projection').

为了解决这个问题,我在/ public/stylesheets中创建了符号链接ln -s tmp/stylesheets/screen.css public/stylesheets/screen.css,这似乎有效.

有没有办法解决这个问题而不使用符号链接,也许是通过改变Rails中的一些配置?我没有取得太大的成功.

这是我的config/initializers/compass.rb:

require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!

# Required for Heroku:
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))

Compass::AppIntegration::Rails.initialize!

Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')

Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
    :urls => ['/stylesheets'],
    :root => "#{Rails.root}/tmp")
Run Code Online (Sandbox Code Playgroud)

这是我的config/compass.rb:

project_type = :rails
project_path = Compass::AppIntegration::Rails.root

# Set this to the root of your project when deployed:
http_path = "/"

# Necessary for Heroku (original commented out:
css_dir   = 'tmp/stylesheets' …
Run Code Online (Sandbox Code Playgroud)

heroku ruby-on-rails-3 compass-sass

5
推荐指数
1
解决办法
2652
查看次数

Vim配置特定的文件类型

我正在努力使用.vimrc来根据文件类型应用特定的配置.根据此处autocmd FileType建议,我尝试应用基于文件类型的配置.这是我在.vimrc中的内容:

autocmd FileType tex call Tex_config()
  function Tex_config()
    let g:LatexBox_viewer = 'skim'
    let g:LatexBox_latexmk_options = '-pvc'
    let g:tex_flavor = "latex"
    setlocal spell spelllang=en_ca
  endfunction
Run Code Online (Sandbox Code Playgroud)

我可以用以下函数调用函数Tex_config():debug Tex_config:Vim愉快地通过该函数.所以,一切似乎都应该有效.

但是,当我发出:set filetype=tex一些奇怪的事情时:拼写检查会关闭.当我发出:set filetype=foo拼写检查时.与我希望从此配置代码段发生的情况相反!

任何帮助将不胜感激.这是完整的vimrc(功能在44-50).谢谢.

vim

0
推荐指数
2
解决办法
5110
查看次数