In html.erb I have:
<%= ContactDescribe.where(["contact_describe_id = ?", "12"]).limit(1).pluck(:borrower_or_lender_text) %>
The field is retrieved successfully. But returns an array element. I need to learn how to convert that element to a string.
The issue here is that
where
returns a collection - something similar to an array, just in ActiveRecord - no matter what limit you set on it. To retrieve the information you would use.first
or[0]
since you always only return one object.But, since you are looking for a specific
ContactDescribe
object. Do this instead:Additionally there two things you should improve in your code.
1: Logic should go into the controller or the model. A view is solely here to show objects.
2: What is up with the
contact_describe_id
field? Why not call itid
. It seems redundant. Isn'tuser.id
more convenient thanuser.user_id
?