user2693845
user2693845

Reputation:

change input data on rails model and save as another field

On a Rails model I have two fields :title and :text_id; text_id is a standardized format of Title i.e title = "Some Movie", text_id = "some-movie". In the model I have the following code:

before_save :get_link
def get_link
  self.text_id = 
end

What should self.text_id be equal to, to enable the formatting of title?

Upvotes: 0

Views: 110

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 3427

you can do

self.text_id = self.title.downcase.gsub(" ","-")

Upvotes: 4

Related Questions