ruby on rails - Render partial collection with association -


i trying render partials collection of @entries shared view.

in 1 controller, doing directly render @entries in view.

<%= render(:partial => '/shared/entry', :collection => @entries) %> 

on controller, doing through bookmarks. result, collection @bookmarks.entries

<%= render(:partial => '/shared/entry', :collection => @bookmarks.entries) %> 

here /shared/_entry.html.erb :

  <div>     <%= link_to_unless_current entry.tag_list, tag_path(entry.tag_list) %>   </div> 

i following error bookmark controller, other controller works fine:

undefined method `tag_list' #<bookmark:0x007fad659b32b8> 

it looks happens because thought collection @bookmarks.entries, still recognizing bookmark , not entry. if change view following, works on bookmark, fails on other controller:

  <div>     <%= link_to_unless_current entry.entry.tag_list, tag_path(entry.entry.tag_list) %>   </div> 

how can make bookmark collection have entries?

what's happening here you've used wrong syntax mistake, , happens there method name you've used, existing in rails/ruby already.

if expecting this

@bookmarks.entries 

to return list of entry objects, won't. if @bookmarks collection of bookmark objects, , @bookmark has_many :entries, , want entries associated bookmarks, @bookmarks.collect(&:entries).flatten.uniq.

so, syntax wrong, , should break, except happens enumerable module, included in rails collection class, has method called "entries", returns array of items, in case bookmark objects. so, partial expecting entry , it's getting bookmark, , that's error telling you: you're calling tag_list on bookmark object.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -