-3

this is the query :

SELECT COUNT(*)
    FROM public.member_roles , public.members , public.users
    WHERE public.users.id = public.members.user_id AND public.members.id = public.member_roles.member_id AND public.member_roles.role_id = 4 ; 

in my views if this query return 1 , a text area is ganna be disabled

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
  • Do you mean in Ruby? or Do you mean in Rails? Moreover, how is your database schema wrt users, members and member_roles? – Rohit Jangid Mar 14 '16 at 12:04
  • yes i mean in ruby in my controller , i wanna generate an instance variable , and use it in the view , i'm sorry if my question is a little stupid but i'm a newbie in ruby on rails and i'm really stuck – achref rezgui Mar 14 '16 at 13:41
  • question is fine I think why it put on hold? many time we fetch such situation. I was in big trouble for the same situation and I posted answer here – Guru Mar 15 '16 at 06:37

1 Answers1

0

in rails

ActiveRecord::Base.connection.execute(your_sql_here)

you can find more info on this question. Hope this help you.

this will return Mysql2::Result object (if you are using mysql db and mysql2 gem. I belive for PG also it give similar object. to fetch data from it. here is a docs for Mysql2::Result.

Community
  • 1
  • 1
Guru
  • 1,303
  • 18
  • 32
  • @manag = ActiveRecord::Base.connection.execute("(SELECT COUNT(*) FROM public.member_roles , public.members , public.users WHERE public.users.id = public.members.user_id AND public.members.id = public.member_roles.member_id AND public.member_roles.role_id = 4)") – achref rezgui Mar 14 '16 at 14:46
  • this actually worked for me but i steal don't know how to use @manag value – achref rezgui Mar 14 '16 at 14:47
  • use manage.first.first it will give you count. to look how this object is what it exactly have you need to log @manage.to_json – Guru Mar 15 '16 at 06:31
  • thanks a lot bro , i'm really stuck with ruby , i'm passing my final year project with ruby i thought that it's easy but here i am , here is my skype : achref_rezgui add me i'm sure i'm ganna need ur experience – achref rezgui Mar 15 '16 at 15:17