Ruby On Rails 3.2.3 - Displaying Information From Two Models On The Same View -
i trying display country name on view. have user model country_id belongs_to :countries. have country model id, iso & name has many :users.
this have in controller show view: @user = user.find(params[:id])
i thought relationship setup user.country.name or user.countries.name , country name. following error, both in view or in user controller. not matter if have user, country or countries capitalized or not.
failure/error: click_button "save changes" actionview::template::error: undefined local variable or method `user' #<#:0x007fb9548a7ae0>
i thought try in view: country.find(@user.country_id).name
this works expected in rails console. showing correct country id value want name for. stated when command in rails console correct value. in console first assigned @user in controller. afterwards country.find command. in view following error on country.find command:
failure/error: click_button "save changes" actionview::template::error: couldn't find country id=1
when display value looks this:
#<country:0x007ffd6bf9ac20>
i same error when created instance variable @country_name set country.find command. i'm lost because united states record has id = 1 in country , can find in rails console.
i have checked web, including stack overflow. similar question showing information 2 models has been asked number of times here. have not been answered except 2 options tried cannot work. once can working create user helper this.
Comments
Post a Comment