Returning empty value in each statement

7 views
Skip to first unread message

Deepak Sharma

unread,
Jul 25, 2016, 4:25:01 AM7/25/16
to rubyonra...@googlegroups.com
In my application I'm rendering comment part with each statement but
getting an unusual response in it. An empty comment is always been
there. I'm using Rails 4 with materialize css. This is how looks [1]
like.

Here is my code

<div class="s12 m7 l8 col">
<ul class="collection with-header">

<li class="collection-header">
<h5>Comment's for you</h5>
</li>

<% @student.comments.each do |comment| %>
<li class="collection-item">
<!-- Content in single row -->
<div>

<%= comment.content %>

<% if comment.user_id == current_user.id ||
current_user.try(:admin?) %>
<%= link_to [comment.student, comment], method: :delete, class:
"secondary-content" do %>
<i class="material-icons">delete</i>
<% end %>
<% end %>
</div>
</li>
<% end %>
</ul>
</div>


[1] : http://www.awesomescreenshot.com/image/1422159/fbabde9acca44d7813726991a087eb40


--
Cheers!

Deepak Kumar Sharma
Guru Nanak Dev Engineering College
India!

Blog: http://deekysharma.wordpress.com

Colin Law

unread,
Jul 25, 2016, 4:31:14 AM7/25/16
to Ruby on Rails: Talk
You have not made it clear exactly what the problem is. Which line in
the above is not doing what you expect?

Colin

Deepak Sharma

unread,
Jul 25, 2016, 5:01:01 AM7/25/16
to rubyonra...@googlegroups.com
On Mon, Jul 25, 2016 at 1:59 PM, Colin Law <cla...@gmail.com> wrote:
> You have not made it clear exactly what the problem is. Which line in
> the above is not doing what you expect?

Problem is In below mentioned each statement part

<% @student.comments.each do |comment| %>
<li class="collection-item">
<div>

<%= comment.content %>

</div>
</li>
<% end %>


It's returning empty value, I checked it in database but nothing there.

Colin Law

unread,
Jul 25, 2016, 5:05:02 AM7/25/16
to Ruby on Rails: Talk
On 25 July 2016 at 10:00, Deepak Sharma <deeky....@gmail.com> wrote:
> On Mon, Jul 25, 2016 at 1:59 PM, Colin Law <cla...@gmail.com> wrote:
>> You have not made it clear exactly what the problem is. Which line in
>> the above is not doing what you expect?
>
> Problem is In below mentioned each statement part
>
> <% @student.comments.each do |comment| %>
> <li class="collection-item">
> <div>
>
> <%= comment.content %>
>
> </div>
> </li>
> <% end %>
>
>
> It's returning empty value, I checked it in database but nothing there.

Well if there is nothing in the database then why would you expect it
to show something in the view?

Colin
Reply all
Reply to author
Forward
0 new messages