当我从MySQL数据库中检索用户信息时,我得到一些追加到列值的垃圾字符,并且某些列值不显示 - 但数据可用在数据库中。获取用户信息 - 在Rails 3中获取垃圾字符
这里是用于以检索用户信息代码:获得
user_controller.rb
edit_user = User.find(params[:id])
@realname = edit_user.realname - value is displayed properly
@username = edit_user.username - value is displayed properly
@email = edit_user.email - value is displayed by junk characters - but value is not displayed in rails console and value can be seen in mysql database.
即电子邮件值为0 /,job_desc是0/ 电话值1111/ 地址值作为办公室/
@phones = edit_user.phones
@phones.each do |phone|
if phone.phone_type == "Office"
@phone1 = phone.number
elsif phone.phone_type == "Mobile"
@phone2 = phone.number
elsif phone.phone_type == "Home"
@phone3 = phone.number
end
end
user.rb - model:
class User < ActiveRecord::Base
has_many :phones
has_many :addresses
end
phone.rb
class Phone < ActiveRecord::Base
belongs_to :user
end
address.rb
class Address < ActiveRecord::Base
belongs_to :user
end
任何人都可以引导我在哪里我犯错或建议我一个方法来正确获取用户信息没有垃圾字符?
感谢ü 苏德赫
字符编码问题的结果,也许? –
我没有编码任何东西 - 我们只是保存和回顾记录。 – sudhir