ruby on rails - Paper trail display has many objects -


I'm using paper trail gem to track version changes on the order web application. I have trouble displaying has_many versions

Order Model:

  class command & lt; ActiveRecord :: Base has_paper_trail has_many: line_items, dependent :: deleted, inverse_of :: order, order: "position", autosave: true end   

line item model:

  Class LineItem & lt; Order Controller:  
  @ order = order.find (params [: id] order type: related to base :: order, inverse_off :: line_itange_pages_toile_p / end 

) @Version = PaperRail :: Versions. (ITIID: Params [: ID]). Order ('Created AASC') @line_itsnaments = lineItim.find_all_b_order_id (param [: id]) @line_itim_version = @line_item. Virus

History html:

  & lt;% @ line_item_versions.each_with_index. Edition, index | & Gt%; & Lt; B & gt; Version: & lt; / B & gt; & lt;% = Index + 1% & gt; & Lt; Br / & gt; Event ID: & lt;% = version.id% & gt; & Lt; Br / & gt; & Lt; P & gt; Target: & lt; / P & gt; & Lt;% = version.item_type% & gt; & Lt; Small & gt; (Id: & lt;% = version.item_id% & gt;) & lt; / Small> & Lt; P & gt; Action & lt; / P & gt; & Lt;% = version.event% & gt ;; & Lt; Br / & gt; & Lt;% end% & gt;   

The problem .versions works when a single object (from .find ) is found. However, when an array of objects (from .find_all_by ) is passed to .versions , this error returns

  undefined Method for version # of & lt; Hex: 0x007f859d37eb30 & gt;    

You are defining:

  @ Line_items = LineItem.find_all_by_order_id (params [: id])   

Which means @line_items is an array of many linear records. Then, you call:

  @line_item_versions = @ line_items.versions   

but .versions method is an example method LineTime (There is more version in a line_itum ). Due to this error, undefined method 'ARA' for 'version' ( @line_items here is an array).


The problem to solve it, I think you should do the following (but there are several options depending on what you want to do):

  & lt;% @ line_items.each do | Line_item | & Gt%; & Lt;% = line_item.name% & gt; & Lt;% line_item.versions.each_with_index | Edition, index | & Gt%; & Lt; B & gt; Version: & lt; / B & gt; & Lt;% = Index + 1% & gt; & Lt; Br / & gt; Event ID: & lt;% = version.id% & gt; & Lt; Br / & gt; & Lt; P & gt; Target: & lt; / P & gt; & Lt;% = version.item_type% & gt; & Lt; Small & gt; (Id: & lt;% = version.item_id% & gt;) & lt; / Small> & Lt; P & gt; Action & lt; / P & gt; & Lt;% = version.event% & gt ;; & Lt; Br / & gt; & Lt;% end% & gt; & Lt;% end% & gt;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -