method_missing not picking up custom attributes?

瀏覽次數:57 次
跳到第一則未讀訊息

Fireborn Silvaranth

未讀,
2014年2月14日 下午3:41:442014/2/14
收件者:ruby-...@googlegroups.com
Maybe I'm not getting something but I was looking at the method_missing documentation
 
 
(Object) method_missing(m, *args, &block)
 
You can add whatever you want to the locale file, and it will get caught here. E.g., in your locale file, create a
name:
  girls_name: ["Alice", "Cheryl", "Tatiana"]

Then you can call Faker::Name.girls_name and it will act like #first_name

 
I added Faker::Config.locale = :en to environment.rb
 
Added
en:
 company:
  job_title: ["Accountant", "Customer Service Rep", "CEO"]
to en.yml
 
attempted to call Faker::Company.job_title
and get an undefined method 'job_title' error
 
Is this not correct?

Conrad Taylor

未讀,
2014年2月14日 下午4:45:112014/2/14
收件者:ruby-...@googlegroups.com
Fireborn, the method, job_title, needs to be defined on the class, Faker::Company.  Are you working in a fork of the original project?

--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/groups/opt_out.


Think different and code well,

Conrad Taylor

Fireborn Silvaranth

未讀,
2014年2月15日 下午1:06:202014/2/15
收件者:ruby-...@googlegroups.com
I figured this out.

You just need to add faker: above the custom lists in your locale file

In en.yml

en:
faker:


company:
job_title: ["Accountant", "Customer Service Rep", "CEO"]

Now calling Faker::Company.job_title will return one of the list entries.

The documentation was just lacking that one little line.

回覆所有人
回覆作者
轉寄
訊息已遭刪除
0 則新訊息