Dunque, nella classe BookmarksController il metodo "show" è il seguente:
def show
@bookmark = Bookmark.find(params[:id])
@bookmark.page = @page
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @bookmark }
end
end
e nella relativa vista "show.html.erb" ho inserito il seguente riferimento:
Content:
<%=h @bookmark.page.content %>
Dentro i due modelli ("bookmark" e "page") ho inserito le seguenti relazioni:
class Bookmark < ActiveRecord::Base
has_oneage, :select => :content
(etc.)
class Page < ActiveRecord::Base
belongs_to :bookmarks
end
L'errore, quando faccio richiamare il metodo "show", è il seguente:
NoMethodError in Bookmarks#show
Showing app/views/bookmarks/show.html.erb where line #18 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.content