dynamic data - Variable symbol in Params object in rails -


मेरे पास निम्न कोड है:

  @ profile.update_attributes (params [: xxxx_profile] )  

जहां xxxx या तो पुरुष या महिला के लिए खड़ा है मूल रूप से फ़ॉर्म सबमिट पास या तो female_profile [foo] या male_profile [foo] का सेट भेजता है और मैं इसे तदनुसार बदलना चाहता हूं। मान लें कि मेरे पास एक स्ट्रिंग है जिसे xxxx के एवज में डाला जा सकता है, मैं इसे कैसे गतिशील रूप से बना सकता हूं?

धन्यवाद।

ऐसा कुछ करने की कोशिश करें:

  @ profile.update_attributes (params [" # {लिंग} _profile ".to_sym])  

या, आपको किसी प्रतीक को परिवर्तित किए बिना स्ट्रिंग में प्रवेश करने में सक्षम होना चाहिए, क्योंकि पैरामीटर के लिए रेल एक हैशविथइंडिफ़ेन्चसी का उपयोग करता है:

  @ profile.update_attributes (params ["# {gender} _प्रोफाइल "])  

Comments

Popular posts from this blog

iphone - How do I make a UIPickerView in a UIActionSheet -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -