English 中文(简体)
铁路3:向示范方法过渡的备选办法
原标题:Rails 3: Pass options to model method

这是我的模式(订阅)方法:

  def activation_codes(options = {})
    if options[:first]
      self.group.group_codes.first
    else
      self.group.group_codes
    end
  end

我试图以这种方式呼吁采用这种方法:

sub = Subscription.where(:subscription_limit => -1).first
sub.activation_codes {:first}

出于某种原因,正在对else 进行评估。

最佳回答

您需要通过 Hash 来使用 > activation_code 的方法, 才能使其如预期的那样有效, 例如 :

sub.activation_codes({:first =>  some value })

但目前您正在通过 Symbol

问题回答

暂无回答




相关问题
Remove ActiveRecord in Rails 3

Now that Rails 3 beta is out, I thought I d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...

When will you upgrade your app to Rails 3? [closed]

Now that the Rails 3 beta is here, let s take a little straw poll. Please tell us briefly what your application does and when you will upgrade it to Rails 3. Or, if you re not planning on upgrading ...

Bundler isn t loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I ...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar....

concat two fields activerecord

I m so used to oracle where you can simply concat(field1, , field2) but if I m using activerecord to find the field1 and field2, and I need a space in between, how do I accomplish this? Cheers ...

热门标签