Rails view is printing certain values we want from a hash and then the full hash - WHY? -


We are trying to make a feed of comments and articles submitted, calling and showing only certain attributes of each We are able to get a type of feed, but the page is also returning a hash of all the attributes of the articles and comments. See below:

Controller:

  def show @ user = user.fund (param [: id]) # @ feed = (Article + all + comment.) .sort {|! A, B A.updated_at & lt; = & Gt; B.updated_at} .reverse.take (10) Comment = Comment.All comments_are = [] Comments.Each | F | Comment_info = {} comment_info ['feed_text'] = f.commenter + comment_info ['TIME_STAMP'] = f.updated_at comments_array & lt; presents a goal '; & Lt; Comment_info end articles = Article.all articles_array = [] is articles.each. | F article_info = {} article_info ['feed_text'] = 'A new goal has been created:' + f.title article_info ['TIME_STAMP'] = f.created_at articles_array & lt; & Lt; Article_info end @feed = (comments_array + articles_array) .sort! {| A, B A ['Time_stamp'] & lt; = & Gt; B ['time_stamp']}. See Reverse.take (10) end  

:

  & lt; P & gt; & Lt;% = @ feed.each do | F | | & Gt%; & Lt; P & gt; & Lt;% = f ['feed_text']% & gt; & Lt; / P & gt; & Lt;% end% & gt; & Lt; / P & gt;  

What's shown on the page is as follows:

  #what_we_want:  

2 one

A goal has been presented

A new goal has been created: test 6

A new goal has been created: test2 < / P>

  # what_we_don't_want:  

[{"feed_text" => "2 presents a goal", "TIME_STAMP" => Thursday, 31 July 2014 UTC 00: 00}, {"feed_text" => "Presenting a new target", "TIME_STAMP" => Thursday, 31 July 2014 19:27:31 UTC 00: 00}, {"feed_text" => "One Or target: test 6 "," TIME_STAMP "=> Thursday, 31 July 2014 19:27:19 UTC 00: 00}, {" feed_text "=>" A new goal has been created: test2 "" TIME_STAMP " => Thursday, 31 July 2014 14:45:09 UTC 00: 00}]

We do not understand why the page keeps showing both #what_we_want and # what_we_don't_want.

want to replace you

   

  & lt;% @ feed.each do | F | & Gt%;   means to evaluate / execute code and insert it in html which means that  and <; Lt;%  means just evaluation / execution of code 


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -