0

I am running the following active record query

Keyword.joins(:questions, :users, :associations).select("questions.*, keywords.keyword").where(users: {id: @user.id})

and presenting the results using wice_grid using the following code -

<%= grid(@questions, show_filters: :false) do |g|
  g.column name: 'ID', attribute: 'id', filter: false
  g.column name: 'Question', model:'Question', attribute: 'question'
  g.column name: 'Keyword', model:'Keyword', attribute: 'keyword'
end %>

The question attribute gets populated fine, but the keyword attribute shows up in hexadecimal value such as #< Keyword:0x00000104eb00a0>. Any idea why? Any help is highly appreciated.

amey1908
  • 157
  • 3
  • 11
  • Does `@questions.first.question` return a value you expect? – franksort Feb 21 '14 at 03:41
  • @franksort - Yes, it returns the right value. Even `@questions.first.keyword` returns the right value. But surprisingly, it does not do it in wice_grid – amey1908 Feb 21 '14 at 03:44

2 Answers2

0

Are you sure you should be using a <%= instead of a <% tag? That displays the return value of any function, so if grid is returning the keyword object, that would be what is getting displayed.

kddeisz
  • 5,162
  • 3
  • 21
  • 44
  • I am sure it needs <%= because it needs to print it. Also the documentation on wice_grid says so. :) I agree with you that its returning the keyword object, but I don't understand why is that. If I change the query to `Keyword.joins(:questions, :users).select("questions.*, keywords.keyword").where(users: {id: @user.id})`, it works fine. Not sure why it doesn't work with the query in the original question. – amey1908 Feb 21 '14 at 03:51
0

From https://github.com/leikind/wice_grid#queries-with-join-tables:

Please note that the blockless definition of the column only works with columns from the main table and it won’t work with columns with :model

<%= grid(@questions, show_filters: :false) do |g|
  g.column name: 'ID', attribute: 'id', filter: false
  g.column name: 'Question', model:'Question', attribute: 'question'
  g.column name: 'Keyword', model:'Keyword', attribute: 'keyword' do |question|
    question.keyword.keyword
  end
end %>
franksort
  • 3,093
  • 2
  • 19
  • 27