开发者

Is it possible to titleize in IRB?

开发者 https://www.devze.com 2023-01-03 05:11 出处:网络
I tried this : User.find(1).update_attribute(\'first_name\', \'#{first.name.titleize}\') => /#{first.name.titleize}

I tried this :

User.find(1).update_attribute('first_name', '#{first.name.titleize}')

=> /#{first.name.titleize}

I am开发者_Go百科 not sure any other way to do this.

Many thanks


First, You need to use double quotes, ruby does not interpolate the embedded variable in single quotes.

Second, you need to bind the user to a variable in order to access the first_name attribute.

This should work:

u = User.find(1)
u.update_attribute(:first_name, u.first_name.titleize)
0

精彩评论

暂无评论...
验证码 换一张
取 消