arup rakshit

Joined

80 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Performance increase over group_by

Thanks for your suggestions!

Posted in Performance increase over group_by

Thanks again!

How can I refactor the view code, and extract out as much as Ruby code from that ? What is your suggestion regarding the searching as you mentioned in your earlier comment?

Posted in Performance increase over group_by

Thanks for your reply!

No, I am just trying to display users names group by location/age/department etc. Currently nothing I think about for searching.

Posted in Performance increase over group_by

How can I write the below operation, being handled by group_by Ruby method, in terms of DB specific query?

def list_users
    @search_by_options = [:age, :location, :department, :designation]
    @users = User.all.group_by { |user| user.public_send(params[:search_by] || :location) }
  end

Corresponding view code is as below :-

<%= form_tag list_users_users_path, :method => 'get' do %>
  <p>
  <%= select_tag "search_by", options_for_select(@search_by_options) %>
  <%= submit_tag "Submit"%>
  </p>
<% end %>
<% @users.each do |grouping_key, users| %>
  <p> <%= grouping_key %> : <%= users.map(&:name).join("||")%></p>
<% end %>
<%= link_to "Back to Main page", root_path %>