5 Create Message Part 6


#1

I am getting an error saying:Screenshot_1
I do understand that the error message is saying that @message is empty but I don’t understand why. I typed it exactly the way it asked me to but still get error message. I used the solution and noticed that bit of code wasn’t even entered in the end so a bit confused on that.
Solutions would be helpful to make me understand the reason for the piece of code entered there and why I was getting an error message

Thanks


#2

Not sure why a second (nested) loop would be needed. There is no scoped data for @message.

    <% @messages.each do |message| %>
    <div class="message">
      <p class="content"><%= message.content %></p>
      <p class="time"><%= message.created_at %></p>
    </div>
    <% end %>

#3

Could this be an error with the solution that was given to me?


#4

What solution were you given? On which exercise page (link, please)?


#5

https://www.codecademy.com/courses/learn-rails/lessons/one-model/exercises/one-model-create-messages-i?action=resume_content_item
Its not giving me an option to show the solution again because I completed it and started again but this is where I left off and I had the problem. Can you see where I’m going wrong?


#6

I cannot see your code, only mine, which is given above in the spoiler. Can you post the index.html.erb file from the message view?


#7

There is a screenshot of my solution:


#8

Did you write the following into app/views/messages/new.html.erb?

    <!-- Your code here -->
    <%= form_for(@message) do |f| %>
    <div class="field">
      <%= f.label :message %><br>
      <%= f.text_area :content %>
    </div>
    <div class="actions">
      <%= f.submit "Create" %>
    </div>
    <% end %>

#9

Yes I did, exactly the way they showed me.


#10

I’ve invited a member with more Rails experience to chip in his point of view. Might be a little later this afternoon.


#11

@betamaster85053, I went through the exercise and didn’t encounter any errors. Could you copy/paste the full contents of your app/views/messages/new.html.erb file here, please?


#12

Not a screenshot, but rw text, please.


#13
<div class="header">
  <div class="container">
    <img src="http://s3.amazonaws.com/codecademy-content/courses/learn-rails/img/logo-1m.svg">
    <h1>Messenger</h1>
  </div>
</div>

<div class="create">
  <div class="container">
   	<%= form_for(@message) do |f| %>  
  		<div class="field"> 
    		<%= f.label :message %><br> 
    		<%= f.text_area :content %> 
  		</div> 
  		<div class="actions"> 
    		<%= f.submit "Create" %> 
  		</div> 
		<% end %>
  </div>
</div>

#14

That code is correct, and worked for me. The only suggestion I have is to reset the exercise and go through again. Going through the exercise in a different browser might help too.


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.