I have two table: bids
and credit_operations
. In my models I have;
bid.rb: has_one :credit_operation
credit_operation.rb belongs_to :bid
In credit_operation table I have bid_id
column. How can I access some attributes in the credit_operations
table from bids_controller.rb
?
to help others: The error was being produced because there was an empty attribute in the field than I was accessing.
meaning bid.credit_operation
could not work. but testing first made it work. so I used:
bid.creditoperation_id ? bid.creditoperation.name : ""
testing first if it is present, if true then bid.creditoperation.name
is returned, otherwise returns empty
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.