与思维狮身人面像的深层联系和狮身人面像指数?

目前我有ff表: Teams id Team_User team_id, user_id Users user_id Item id team_id 和ff。 模型: Team has_and_belongs_to_many :users User has_and_belongs_to_many :teams Item belongs_to :audit_team, :class_name => “Team”, :foreign_key => “team_id” 为什么我要尝试存档是为了让Sphinx索引与Item关联的所有user_id,我想出了这个索引定义: define_index do has audit_team.users(id), :as => :team_users end 我不确定这是否正确。 此外,Thinking Sphinx没有为此构建配置。 当我重建,重新索引并运行应用程序时,ff。 出现错误: index ncpar_core: no such filter attribute ‘team_users’ 可能是什么问题,我该如何存档? 非常感谢你

将String拆分为值数组

输入字符串: – str = ‘”2014-09-04 21:12:05″ 5469687123030383463 192.168.1.2 4 7879 0 43 “www.test.com/” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36” 404 123 F 21549 50 0 – Test1 当我用空格分开时: – str.split(‘ ‘) => [“\”2014-09-04”, “21:12:05\””, “5469687123030383463”, “192.168.1.2”, “4”, “7879”, “0”, “43”, “\”www.test.com/\””, “\”Mozilla/5.0”, “(X11;”, “Linux”, “x86_64)”, “AppleWebKit/537.36”, “(KHTML,”, “like”, “Gecko)”, “Chrome/35.0.1916.153”, “Safari/537.36\””, […]

Ruby on Rails – 坚持Hartl Book第9.3.3章,未定义方法sign_in

我正在研究Hartl书籍的9.3.3并继续坚持使用 SessionsController的未定义方法`sign_in’:0x00000100c0da90 我知道这是因为sign_in方法位于sessions_helper文件中,该文件由模型而不是控制器拾取。 Hartl书不需要“包含SessionsHelper”系列。 如果我把那个hack,我假设我不应该,那么它最终会让我失去另一个错误undefined方法current_user 这是代码 SessionsController.rb class SessionsController < ApplicationController def new @title = "Sign in" end def create user = User.authenticate( params[:session][:email], params[:session][:password]) if user.nil? flash.now[:error] = "Invalid email/password combo." @title = "Sign in" render 'new' else sign_in user redirect_to user end end def destroy end 和sessions_helper.rb module SessionsHelper def sign_in(user) cookies.permanent.signed[:remember_token] = […]

Rails:通过form_for check_box为HABTM关系分配多个参数

我是第一个自己项目的铁杆菜鸟。 我使用has_and_belongs_to_many关系链接了两个模型:Wine和Shop。 为了简单起见,葡萄酒可以在不同的商店出售,特定的商店可以出售许多不同的葡萄酒。 以下是模型: class Shop < ActiveRecord::Base has_and_belongs_to_many :wines end class Wine < ActiveRecord::Base has_and_belongs_to_many :shops end 我的目标是创建一个表单来创建Wine的实例,包括可以购买葡萄酒的商店。 这是我的wines_controller: def new @wine = wine.new @shops = Shop.all respond_to do |format| format.html # new.html.erb format.json { render json: @wine } end end def create @wine = Wine.new(params[:wine]) params[:shops].each do |id| @wine.shops << Shop.find(id) end end […]

Ruby Rack Heroku:提供静态文件

我遵循Heroku指南使用Ruby Rack( https://devcenter.heroku.com/articles/static-sites-ruby )部署静态文件,但除了index.html之外,我无法访问\public任何HTML文件。 也就是说, localhost:9292/test.html仍然映射到index.html 。 (我的所有样式和js文件都正确提供)。 下面是我的config.ru文件。 我知道什么是错的,但不确定有效的解决方案? use Rack::Static, :urls => [“/images”, “/js”, “/css”], :root => “public” run lambda { |env| [ 200, { ‘Content-Type’ => ‘text/html’, ‘Cache-Control’ => ‘public, max-age=86400’ }, File.open(‘public/index.html’, File::RDONLY) ] }

文件系统爬虫 – 迭代错误

我目前正在使用以下代码构建文件系统爬网程序: require ‘find’ require ‘spreadsheet’ Spreadsheet.client_encoding = ‘UTF-8’ count = 0 Find.find(‘/Users/Anconia/crawler/’) do |file| if file =~ /\b.xls$/ # check if filename ends in desired format contents = Spreadsheet.open(file).worksheets contents.each do |row| if row =~ /regex/ puts file count += 1 end end end end puts “#{count} files were found” 我收到以下输出: 0 files were found […]

为什么这需要从rake中失败但在明确运行时成功?

帮助我理解为什么这个项目的测试在直接执行时运行但在通过rake运行时不运行。 通过Rake TestTask运行时的错误: ** Execute test /home/myockey/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I”lib:test” “/home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb” “test/unit/data_test.rb” “test/unit/station_test.rb” “test/unit/raw_test.rb” “test/unit/parser_test.rb” “test/unit/report_test.rb” :29:in `require’: no such file to load — test/unit/../metar_test_helper.rb (LoadError) from :29:in `require’ from test/unit/data_test.rb:4:in `’ from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load’ from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `block in ‘ from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each’ from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `’ rake aborted! 当我直接运行脚本时,我得到以下内容: myockey@myockey-K61IC:~/opt/joeyates-metar-parser-cdca19f/test/unit$ ruby data_test.rb Loaded suite data_test Started …………………………………………… […]

Nokogiri在heroku上产生不同的结果?

我有一个非常奇怪的问题,我很感激帮助追踪它。 我正在使用nokogiri gem解析一些html,我正在解析一个有奇怪字符的文件。 不完全确定这个角色是什么,在vim中它显示为^ Q. 在我自己的计算机上,一切正常,但是在heroku上它插入当它击中角色时,选择器只返回奇怪角色之前的元素。 为了说明: Nokogiri::HTML( open(“http://thoms.net.nz/e2.html”)).css(“body div”).count在heroku上Nokogiri::HTML( open(“http://thoms.net.nz/e2.html”)).css(“body div”).count为1,在计算机上Nokogiri::HTML( open(“http://thoms.net.nz/e2.html”)).css(“body div”).count为2。 – 可以从http://thoms.net.nz/e2.html下载包含此字符的文件。 我的计算机和heroku都使用ruby 1.9.3运行nokogiri 1.5.5。

为什么没有值的变量返回true为空? 在视图中使用时)?

empty? 对于nil类,方法是未定义的,所以当你尝试nil.empty? 它在控制台中给出: undefined method empty? for nil:NilClass undefined method empty? for nil:NilClass 我在application_helper.rb中创建了这个方法: def full_title(page_title) base_title = “my app” if page_title.empty? base_title else “#{base_title} – #{page_title}”.html_safe end end 在我的应用程序布局中,我在标题标签上调用它,如下所示: !!! %html %head %title #{full_title(yield(:title))} … … %body = yield 在我的每个视图中,我添加了provide(:title, “something”)用于将字符串传递给此辅助方法。 但是,当我不使用provide(:title, “something”)它看起来像page_title.empty? 返回true! 我的问题是为什么page_title.empty? 返回true。 我认为当我不使用provide(:title, “something”) ,page_title变量为nil,它是否不会引发任何错误? 如未undefined method empty? for nil:NilClass […]

找不到Ruby-SassCompiler的指南针

我有一个小的ruby脚本使用Compass来编译* .scss文件,因为Compass和Sass是基于ruby的我只是直接使用编译器(基于这个SO问题 ): require ‘compass’ require ‘sass’ Compass.add_configuration({ :project_path => ‘.’, :sass_path => ‘css’, :css_path => ‘css’, :output_style => :compressed },’custom’) Compass.compiler.compile(‘css/index.scss’, ‘css/index.css’) 这按预期工作并进行编译,但是,我也得到了这样的信息: Compass.compiler is deprecated. Use Compass.sass_compiler instead. 所以我试着用: Compass.sass_compiler.compile(‘css/index.scss’, ‘test.css’) 什么引发错误,告诉我没有定义类SassCompiler (NoMethodError)。 我真的想使用建议的方法,但我可以使用它,我需要提前做什么? 感谢帮助!