草庐IT

core-data-and-enterprise-iphone-a

全部标签

ruby-on-rails - rails : :inverse_of and Association extensions

我有以下设置classPlayer:playerdodefin_handfind_all_by_location('hand')endendendclassCard:cardsend这意味着以下工作:p=Player.find(:first)c=p.cards[0]p.score#=>2c.player.score#=>2p.score+=1c.player.score#=>3c.player.score+=2p.score#=>5但下面的行为不一样:p=Player.find(:first)c=p.cards.in_hand[0]p.score#=>2c.player.score#=

ruby-on-rails - mongoid中的has_many、has_and_belongs_to_many和embeds_many到底有什么区别?

我知道这不是编程问题,我找不到非常清晰和描述性的解决方案。 最佳答案 Mongoid的documentation很清楚:Embeddedrelationsdescribedocumentswhoarestoredinsideotherdocumentsinthedatabase.Referencedrelationsdescribedocumentsthatreferencedocumentsinanothercollectionbystoringforeignkeydata(usuallyanid)abouttheotherdoc

ruby-on-rails - Capistrano 部署 :migrate and db:migrate run all migrations every time

因此,我正在使用rails(ruby1.9.3p392、rails3.2、sqlite3db)并尝试将无处不在的博客教程代码部署到“生产”服务器(apache、passenger、ubuntu)。我的deploy.rb看起来像这样:require'bundler/capistrano'require'rvm/capistrano'load'deploy/assets'set:rvm_ruby_string,ENV['GEM_HOME'].gsub(/.*\//,"")set:rvm_type,:userset:user,'blah'set:application,'railsTest'

ruby - Codecademy "converting between symbols and strings" ruby 类(class)

这些是Codecademy的说明:Wehaveanarrayofstringswe'dliketolateruseashashkeys,butwe'drathertheybesymbols.Createanewarray,symbols.Use.eachtoiterateoverthestringsarrayandconverteachstringtoasymbol,addingthosesymbolstosymbols.这是我写的代码(提供了strings数组):strings=["HTML","CSS","JavaScript","Python","Ruby"]symbols=[]

ruby - 为什么某些 Ruby 代码在 2.53GHz 上的运行速度是在 2.2GHz Core 2 Duo 处理器上的两倍?

(本题试图找出为什么一个程序在不同的处理器上运行会有所不同,所以它与编程的性能方面有关。)以下程序在配备2.2GHzCore2Duo的Macbook上运行需要3.6秒,在配备2.53GHzCore2Duo的MacbookPro上运行需要1.8秒。这是为什么?这有点奇怪……当CPU的时钟速度仅快15%时,为什么要加倍速度?我仔细检查了CPU仪表,以确保2个内核中没有一个处于100%使用率(以便查看CPU是否忙于运行其他东西)。难道是因为一个是MacOSXLeopard,一个是MacOSXSnowLeopard(64位)?两者都运行Ruby1.9.2。pRUBY_VERSIONpRUBY_

ruby-on-rails - 使用 has_many :through and build

我有三个模型,都用于has_many:through关系。它们看起来像这样:classCompany这加载很好,并且连接是为查询而构建的。但是,每当我做类似的事情时@company=Company.last@user=@company.users.build(params[:user])@user.save#=>true@company.save#=>trueUser记录和CompanyUser记录被创建,但是company_idCompanyUser中的字段记录设置为NULLINSERTINTO`companies_users`(`company_id`,`created_at`,`

sql - 在 AREL 中分组 ands 和 ors

我正在尝试使用arel查询此sql片段的等效项:WHERE(("participants"."accepted"='f'AND"participants"."contact_id"=1)OR"participants"."id"ISNULL)所以我想要(accepted&&contact_id=1)ORNULL这是我在AREL中得到的participants[:accepted].eq(false).and(participants[:contact_id].eq(1).or(participants[:id].is(nil)问题是,这会产生:("participants"."acce

ruby-on-rails - Rails 3.1 和 Ruby 1.9.3p125 : ruby-debug19 still crashes with "Symbol not found: _ruby_threadptr_data_type"

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ruby-debugwithRuby1.9.3?我听说ruby​​1.9.3p125有解决ruby​​-debug19问题的传言,所以根据RVM站点上的说明,我重新安装了1.9.3:$rvmreinstall1.9.3--patchdebug--force-autoconf$ruby-vruby1.9.3p125(2012-02-16revision34643)[x86_64-darwin11.2.0]然后:geminstallruby-debug19将此条目添加到我的Gemfile中:gem'ruby-de

iphone - 设计和 Rails 3 中的 http 身份验证

我有一个使用deviseonrails3的应用程序。我想启用http身份验证,以便我可以从iPhone应用程序向我的网络应用程序进行身份验证。如何从我的iPhone应用程序进行身份验证以进行设计?这安全吗?还是我应该进行不同的身份验证? 最佳答案 从设计的角度来看,您有3个选择:1)使用基本的http身份验证:您的iPhone应用程序有一个secretkey-这是在您的iPhone应用程序代码中烘焙的-用于对网络应用程序的每个请求进行身份验证。Google搜索:“设计基本的http身份验证”2)您可以通过在您的iPhone应用程序中

ruby - `sort_by' : comparison of Array with Array failed (no nil data)

classCustomSorterattr_accessor:start_date,:availabledefinitialize(start_date,available)@start_date=Time.mktime(*start_date.split('-'))@available=availableendendcs1=CustomSorter.new('2015-08-01',2)cs2=CustomSorter.new('2015-08-02',1)cs3=CustomSorter.new('2016-01-01',1)cs4=CustomSorter.new('2015-0