Ruby on Rails Sunday, July 5, 2015

Hello Colin these are the results I got 
>Try
>Role.where(id: user.roleid).select("role_name")

#<Role:0x000000061d80e8>
An invalid value. As I stated in my question this is similar to <% rolename = Role.select("role_name").where(id: user.roleid) %> but "where" and "select" are inter changed. So same invalid value.
 
>Or even better
>user.role.select("role_name")

private method `select' called for nil:NilClass 
Wouldn't work in my case because, I think it requires an Association between user and role table. And there Must be a field on both tables named "role_name". Which doesn't exist
 
>Though I have to ask why you need to do the select?  Why not just use
>Role.where(id: user.roleid).role_name

undefined method `role_name' for #<Role::ActiveRecord_Relation:0x00000005ff4218>
 
>or again even better
>user.role.role_name

 undefined method `role_name' for nil:NilClass
This also need same field name role_name in both tables which doesn't exist.

Thank you

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1f97d633-bccd-402c-972a-d9d74f2f93dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment