Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4619

Treat a model attribute as a symbol

$
0
0

My model has a string field (a short) and it stores it in db which is fine. But I want it always to return a symbol instead of string and, also, I'd like to assign a symbol to this string attribute. What I'm doing now doesn't work.

class MyModel < ActiveRecord::Base  attr_accessible :attr1  def attr1    # self.try(:attr1).to_sym # how to return symbol?  end  def attr1= value   #    super.attr1.to_sym # doesn't work either  endend

How do I reach this?


Viewing all articles
Browse latest Browse all 4619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>