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>

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

If i run @billings in rails console. it outputs the data such as username 
there:

#<Radacct @values={:username=>"1035", 
:calledstationid=>"C8-60-00-95-4B-0F", :acctstarttime=>2015-12-22 10:00:06 
+0800, :acctstoptime=>2015-12-22 10:49:53 +0800}>, #<Radacct 
@values={:username=>"1036", :calledstationid=>"C8-60-00-95-4B-0F", 
:acctstarttime=>2015-12-21 09:39:37 +0800, :acctstoptime=>2015-12-21 
10:39:39 +0800}>

Thank you,
Muhammad Nuzaihan


On Friday, December 25, 2015 at 3:17:06 AM UTC+8, Jeremy Evans wrote:
>
> On Thursday, December 24, 2015 at 11:11:21 AM UTC-8, Muhammad Nuzaihan Bin 
> Kamal Luddin wrote:
>>
>> Hi,
>>
>> I tried to find the manual of sequel combining the result of multiple 
>> queries. The docs using .merge reflects on a very old version of sequel gem 
>> and i am trying to combine the query result into one result. I have looked 
>> at 
>> http://stackoverflow.com/questions/9540801/combine-two-activerecordrelation-objects
>>  
>> but it is only activerecord only and doesn't apply to sequel.
>>
>> Here is the code which i am trying to do.
>>
>> class BillingsController < ApplicationController
>>   def show
>>     @wifis = Wifi.where(user_id: current_user.id)
>>       @wifis.each do |wifi|
>>         billing = 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)
>>         @billings << billing
>>       end
>>   end
>> end
>>
>>
>> I am using @billings << billing to add the data but i got this follow 
>> error:
>>
>> F, [2015-12-24T22:59:01.403150 #17112] FATAL -- : 
>> NoMethodError (undefined method `<<' for nil:NilClass):
>>   app/controllers/billings_controller.rb:6:in `block in show'
>>   app/controllers/billings_controller.rb:4:in `show'
>>
>
> In this case, it is because @billings is not defined, so the result is 
> nil, and you end up calling << on nil, which is not defined, and raises 
> NoMethodError.  I'm guessing you want something like:
>
> 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).first
>       end
>   end
> end
>
> 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