-2

I am using Cancan In my user model there is

ROLES = %w[admin user ram]

I want to bring the value from my own module .

 all= Role.all
 @all.each do |all|
 all.name
 end

Here i can carry all value that are in database from roll model. and i want to keep it inside %w[] like `

ROLES = %w[ all= Role.all
     @all.each do |all|
     all.name
     end]

But I don know the format.

anothermh
  • 9,815
  • 3
  • 33
  • 52
regmiprem
  • 735
  • 2
  • 14
  • 41

2 Answers2

2

Try pluck:

ROLES = Role.pluck(:name)

More info on APIdock: http://apidock.com/rails/ActiveRecord/Calculations/pluck

Mate Solymosi
  • 5,699
  • 23
  • 30
0

%w[] is just a fancy way to create an array. If you want this should work the same way.

ROLES = @all.collect! {|item| item.name }
Pablo Jomer
  • 9,870
  • 11
  • 54
  • 102
  • 1.9.3p194 :001 > %w[admin user ram] => ["admin", "user", "ram"] I know it give such result. I want to bring my users in this format. – regmiprem Aug 15 '12 at 11:08