开发者

retriving user information - getting junk characters appended in Rails 3

When i am tring to retrive user information from mysql database, i am getting some junk characters appended to the column values and some column values are not displayed - but the data is available in database.

Here is code which is used to retrive user info:

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.

i.e. email valu开发者_C百科e obtained is 0/, job_desc is 0/ Phone values as 1111/ addresses values as Office/

@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

Can anyone guide me where i am making mistake or suggest me an approach to get user information properly without junk characters?

Thank u Sudhir


I think there must be something going on outside the code you supplied.

In rails console can you do the following...

u = User.new
u.realname = "1"
u.username = "2"
u.email = "test@something.com"
u.save

x = u.id

u = User.find(x)
puts x.email

And post the results of this

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜