草庐IT

expires_in

全部标签

ruby - Xcode - 配置 : error: no acceptable C compiler found in $PATH

从头开始重建Mac。安装xcode和rvm然后尝试安装ruby但他们都给我:Errorrunning'./configure--prefix=/Users/durrantm/.rvm/rubies/ruby-1.9.3-p125--enable-shared--disable-install-doc--with-libyaml--with-opt-dir=/Users/durrantm/.rvm/usr',pleaseread/Users/durrantm/.rvm/log/ruby-1.9.3-p125/configure.logTherehasbeenanerrorwhilerun

ruby-on-rails - rails : An elegant way to display a message when there are no elements in database

我意识到我正在编写很多与此类似的代码:Youhavenomessages.Ruby和/或Rails中是否有任何构造可以让我跳过它第一个条件?那么当迭代器/循环一次都不会进入时会执行吗?为了示例:Youhavenomessages. 最佳答案 你也可以这样写:Youhavenomessages. 关于ruby-on-rails-rails:Anelegantwaytodisplayamessagewhentherearenoelementsindatabase,我们在StackOverfl

ruby-on-rails - rails : Access to current_user from within a model in Ruby on Rails

我需要在RubyonRails应用程序中实现细粒度访问控制。单个用户的权限保存在数据库表中,我认为最好让相应的资源(即模型的实例)决定是否允许某个用户读取或写入它。每次都在Controller中做出这个决定肯定不会很枯燥。问题是为了做到这一点,模型需要访问当前用户,调用类似may_read?(current_user,attribute_name)的东西。.不过,模型通常无法访问session数据。有很多建议可以在当前线程中保存对当前用户的引用,例如在thisblogpost.这肯定会解决问题。邻近的Google结果建议我在User类中保存对当前用户的引用,我猜这是由应用程序不必同时容

ruby-on-rails - Rails has_many :through Find by Extra Attributes in Join Model

Ruby和Rails的新手,但我现在已经受过书本教育(这显然没有任何意义,哈哈)。我有两个模型,Event和User通过表EventUser连接classUser:event_usersendclassEventUser:event_usersend这个项目是一个日历,我必须在其中跟踪人们为给定的事件注册和刮掉他们的名字。我认为多对多是一种好方法,但我不能这样做:u=User.find:firstactive_events=u.events.find_by_active(true)因为事件实际上没有额外的数据,所以EventUser模型有。虽然我可以做到:u=User.find:fir

ruby-on-rails - 为什么 rake db :migrate:reset not listed in rake -T?

为什么rake-T没有列出一些rake任务?像db:migrate:reset吗?我可以毫无问题地执行它,但为什么它没有列在那里?有没有办法获得真正完整的rake任务列表?%rake-T(in/home/zeus/projects/my_project)rakeabout#ListversionsofallRailsframeworksandtheenvironmentrakedb:create#Createthedatabasefromconfig/database.ymlforthecurrentRails.env(usedb:create:alltocreatealldbsint

ruby - "which in ruby": Checking if program exists in $PATH from ruby

我的脚本严重依赖外部程序和脚本。我需要确定我需要调用的程序存在。手动地,我会在命令行中使用“which”来检查这一点。对于$PATH中的东西,是否有等同于File.exists?的东西?(是的,我想我可以解析%x[whichscriptINeedToRun]但这不是super优雅。谢谢!亚尼克更新:这是我保留的解决方案:defcommand?(command)system("which#{command}>/dev/null2>&1")end更新2:出现了一些新的答案-至少其中一些提供了更好的解决方案。更新3:ptoolsgem向File类添加了一个“which”方法。

ruby - TCP 服务器错误 : Address already in use - bind(2)

几周前Jekyll对我来说工作正常,但现在突然出现以下错误:TCPServerError:Addressalreadyinuse-bind(2)INFOWEBrick::HTTPServer#start:pid=7300port=4000%lsof-i:4000即使端口上没有任何运行。以下是详细信息:%jekyll--versionJekyll0.11.2%wherejekyll/home/bhaarat/.rvm/gems/ruby-1.9.2-p290/bin/jekyll/usr/bin/jekyll%ruby--versionruby1.9.2p290(2011-07-09re

ruby-on-rails - 正确执行 redirect_to :back in Ruby on Rails when referrer is not available

我在使用redirect_to:back时遇到问题。是的,它是推荐人。我经常遇到异常(ActionController::RedirectBackError)"NoHTTP_REFERERwassetintherequesttothisaction,soredirect_to:backcouldnotbecalledsuccessfully.Ifthisisatest,makesuretospecifyrequest.env[\"HTTP_REFERER\"]."我意识到这是由于推荐人不可用造成的。有没有一种方法,例如,可以在访问最后一个页面的每次访问时设置一个session变量,并且

ruby-on-rails - 更改 :id parameter in Routing resources for Rails 的名称

我四处查看如何更改动态参数槽,发现这篇文章完全符合要求。帖子是https://thoughtbot.com/blog/rails-patch-change-the-name-of-the-id-parameter-in基本上它所做的是,如果以下是路线:map.resources:clients,:key=>:client_namedo|client|client.resources:sites,:key=>:namedo|site|site.resources:articles,:key=>:titleendend这些路由创建以下路径:/clients/:client_name/cli

ruby - 你能为 map 提供参数吗(&:method) syntax in Ruby?

您可能熟悉以下Ruby速记(a是一个数组):a.map(&:method)例如,在irb中尝试以下操作:>>a=[:a,'a',1,1.0]=>[:a,"a",1,1.0]>>a.map(&:class)=>[Symbol,String,Fixnum,Float]语法a.map(&:class)是a.map{|x|的简写x.class.在“Whatdoesmap(&:name)meaninRuby?”中阅读有关此语法的更多信息。通过语法&:class,您正在为每个数组元素调用方法class。我的问题是:您可以为方法调用提供参数吗?如果是这样,怎么做到的?比如下面的语法你怎么转换a=[1