forms - How do I so a select input for a STI column in a Rails model? -


I have a model with a single-table succession on the type column:

  class abs & lt; ActiveRecord :: Base type = [dog, cat, hamster] validates_presence_of: name end  

I want to provide a & lt; select & gt; Pages hanging on new and edit:

  & lt;% form_for @model do | F | & Gt%; & Lt;% = f.label: name% & gt; & Lt;% = f.text_input: name% & gt; & Lt;% = f.label: Type% & gt; & Lt;% = f.select: type, pet :: TYPES.map {| T | [T. Haaman_Naw, T.O_s]}%> & Lt;% end% & gt;  

This gives me the following error:

  ActionView :: TemplateError (wrong logic type string (expected module))  

I read to use the aliases for the field #type , because Ruby assumes that the reserved word which is similar to #class I have tried

  class pet & lt; ActiveRecord :: base ... alias_attribute: klass,: type end  

and

  class abdomen & lt; ActiveRecord :: Base ... def klass self.type end def klass = (k) self.type = k end end  

Neither suggestion worked? Strangely, it works fine on my machine (MRI 1.8.6 on RVM), but fails on platforming server (not MRI 1.8.7 on RVM). The main difference between "Ryan Bates" "suggestion self" (which is about the maximum rail)

), And direct access to the property through its implementation suggestion bracket ("[: type] =") is created with your implementation, the method calling ("auto type =")

then try to do something like this:

  class pet & lt; ActiveRecord :: Base ... def klass self [: type] end def klass = (k) self [: type] = k end end  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -