On Friday, December 25, 2015 at 7:23:03 AM UTC-8, Muhammad Nuzaihan Bin 
Kamal Luddin wrote:
>
> Thank you jeremy, i have made some modifications to the code below:
>
> class BillingsController < ApplicationController
>   def show
>     @wifis = Wifi.where(user_id: current_user.id).all
>     @billings =  @wifis.map do |wifi|
>         Radacct.fetch("SELECT 
> radusergroup.username,radusergroup.groupname,radacct.acctstarttime,radacct.acctstoptime
>  
> FROM radusergroup INNER JOIN radacct ON 
> radusergroup.username=radacct.username WHERE calledstationid = ? GROUP BY 
> radusergroup.username", wifi.mac_id).all
>     end
>   end
> end 
>
> I had change .first to .all to show me all records, however when i do 
> .each in my billings view
>
> <% @billings.each do |billing| %>
>   <%= billing.username %>
> <%  end %>
>
> It gives out an error saying:
>
> NoMethodError: undefined method `username' for #<Array:0x000000080a3310>
>

If you use all instead of first, you need to call @billings.flatten!
 

> I used .fetch as i cannot make out the query using sequel DSL and that's 
> probably why the error above.
>

It's definitely possible to use the Sequel DSL for that query, but it's 
unrelated to the error you got.
 
  Radacct.
    join(:radusergroup___g, :username=>:username).
    select_group(:g___username).
    select_append(:g__groupname, :radacct__acctstarttime, 
:radacct__acctstopstime).
    where(:calledstationid=>wifi.mac_id).
    all

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to