Rails 4 not rendering code

93 Views Asked by At

I am trying to render a partial on a page in rails. For some reason the code is not being rendered into html. I have tried taking it out of the partial and just placing it in the profile page but still nothing. I am getting no errors and have restarted the server but still nothing. This is in development mode. Also all code except the message code works fine. Any help would be appreciated. Here is the code.

profile.html.erb

<% unless @pictures.nil? %>
  <div id="container" style="width: 500px; height: 450px;">
    <div id="slides">
      <% @pictures.each do |picture| %>
        <%= image_tag(picture.image.url(:thumbnail)) %>
      <% end %>
      <a href="#" class="slidesjs-previous slidesjs-navigation"><%= image_tag("left.png") %></a>
      <a href="#" class="slidesjs-next slidesjs-navigation"><%= image_tag("right.jpeg") %></a>
    </div>
  </div>
<% end %>

<% render 'message' %>

_message.html.erb

<% form_for @message, :url => messages_create_path do |f| %>
  <% f.hidden_field :from, value: current_user.id %>
  <% f.hidden_field :to, value: @user.id %>
  <% f.text_area :message %><br />
  <% f.submit "Send Message" %>
<% end %>
2

There are 2 best solutions below

1
On BEST ANSWER

To make your form_for code block to render you need to use <%= tag as follows:

<%= form_for @message, :url => messages_create_path do |f| %>
  <% f.hidden_field :from, value: current_user.id %>
  <% f.hidden_field :to, value: @user.id %>
  <% f.text_area :message %><br />
  <% f.submit "Send Message" %>
<% end %>
3
On

To elaborate on vinodadhikary's answer, ERB has output tags and evaluation tags. To evaluate something you would use <% expression %>, and to output you would use <%= output.me %>. The earlier is usually used for flow control in templates, and outputs nothing. The output happens within after a decision is made. The latter is used to output stuff.