html - Can't figure out how to limit result to one hopefully using .group -


i trying create drop-down filter results in table. far working except multiple items being listed.

such as:

clec id: 216 324 216 315 

where want 1 216.

    <select name="by_clecid">       <option value="">all</option>       <% @task_queues.each |task_queue| %> <option value="<%= task_queue.clecid %>"><%= task_queue.clecid %></option><% end %>      </select> 

i thought use .group not sure how use it. appreciated not familiar ruby.

edit: model:

class taskqueue < activerecord::base    require 'task_queue'    self.table_name = "taskqueue"   belongs_to :clec_profile   scope :by_status,     -> status  { where(:status => status) }   scope :by_tasktype,   -> tasktype  { where(:tasktype => tasktype) }   scope :by_clecid,     -> clecid  { where(:clecid => clecid) }   scope :by_taskid,     -> taskid  { where(:taskid => taskid) }   scope :by_hostname,     -> hostname  { where(:hostname => hostname) }    def elapsed_seconds     case status     when "completed"       finishtime - starttime     when "pending"       time.now - starttime     when "waiting", "failed"       0     end   end  end 

some of controller:

class taskqueuescontroller < applicationcontroller   before_action :set_task_queue, only: [:show, :edit, :update, :destroy]   has_scope :by_status, :by_tasktype, :by_taskid,  :by_hostname, :by_clecid    def index     @task_queues = apply_scopes(taskqueue).all     @task_queues = @task_queues.paginate(:page => params[:page], :per_page => 30)   end end 

edit: here's picture better show happening: http://i.imgur.com/sqzzdxc.png show image not enough rep yet.

activerecord provides uniq method generating select distinct ... query. example do

@clec_ids = apply_scopes(taskqueue).uniq.pluck(:clecid) 

if want re-use selected @task_queues, use cousin method array#uniq ensure unique clecids displayed

@clec_ids = @task_queues.map(:clecid).uniq 

in view do

<select name="by_clecid">   <option value="">all</option>   <% @clec_ids |clec_id| %>     <option value="<%= clec_id %>"><%= clec_id %></option>   <% end %>  </select> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -