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
wherereturns 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.firstor[0]since you always only return one object.But, since you are looking for a specific
ContactDescribeobject. 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_idfield? Why not call itid. It seems redundant. Isn'tuser.idmore convenient thanuser.user_id?