मैं निम्नलिखित कोड है:लेखन त्रुटि: गलत तर्क प्रकार स्ट्रिंग (उम्मीद मॉड्यूल)
class ProfileLookup < ActiveRecord::Base
class << self
ProfileLookup.select("DISTINCT category").map{|c| c.category}.each do |category|
define_method("available_#{category.pluralize}".to_sym) do
ProfileLookup.where(category: category).order(:value).all.collect{|g| g.value}
end
end
end
end
जो मूल रूप से देखने डेटा का भार होता है, श्रेणी के द्वारा बाहर अलग हो गए। इसका उद्देश्य डेटाबेस में प्रत्येक श्रेणी के लिए एक विधि बनाना है। रेल कंसोल के माध्यम से, यह कोड अपेक्षित काम करता है:
[email protected] :002 > ProfileLookup.available_genders
ProfileLookup Load (0.6ms) SELECT "profile_lookups".* FROM "profile_lookups" WHERE "profile_lookups"."category" = 'gender' ORDER BY value
=> ["Female", "Male"]
हालांकि, मेरी चश्मा विफल हो रही हैं। निम्नलिखित कल्पना:
Exception encountered: #<TypeError: wrong argument type String (expected Module)>
backtrace:
/Users/fred/code/my_app/spec/models/profile_lookup_spec.rb:5:in `include'
क्या समस्या यहाँ है:
require "spec_helper"
describe ProfileLookup do
its(:available_genders).should include("Male")
its(:available_age_groups).should include("0-17")
its(:available_interests).should include("Autos & Vehicles")
its(:available_countries).should include("United States")
end
के साथ विफल हो?
हमें शामिल-रेखा दिखाएं। जहां भी यह है। –