문제

I tried this :

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

=> /#{first.name.titleize}

I am 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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top