Your'e misdiagnosing your problem. It's working just fine, and the view can definitely see your method, but your method is returning nil
. Your method isn't returning anything.
If the method actually weren't accessible, you'd see an exception to that effect. Ruby doesn't simply resolve unknown methods to nil
.
In the view I was trying to see if pro_user.email.blank? and its nil all the time.
That isn't a valid way of using the value returned by the method you posted. It returns an array.
I also tried @pro_user in the view. Everything prints correctly in the application controller but its nil in the view.
Neither is that. The method returns an array of zero or more email addresses, this is what pluck
does is for. The return value will never respond to .email
. You would need to use pro_email.any?
to test whether the array contains any items.
You also can't simply access @pro_user
. That doesn't invoke the method, that access a member variable which will be nil
by default.
I do <% if pro_user.blank? %> { ..do blah.. }
That's not valid erb syntax. Assuming that your syntax is actually correct, blank?
will return true
for an empty array. The method is returning []
, not nil
. There is no error, you just need to figure out why your query returns zero records.