Search code examples
ruby-on-railscloud9-idecloud9

error while trying to see articles


I am getting this error while going into articles/new.

enter image description here

my code :

new.html.erb :

<h1>Create an article</h1>
<%if @article.error.any? %>
<ul>
    <% @article.errors.full_messages.each do |msg| %>
    <li> <%= msg %> </li>
</ul>



<%= form_for @article do |f| %>

<p>
    <%= f.label :title %>

    <%= f.text_field:title %>

</p>
<p>
    <%= f.label :description  %>
    <%= f.text_area :description %>

</p>
<p>
    <%= f.submit %>

</p>
    end

my articles_controller.erb file :

class ArticlesController < ApplicationController

   def new
     @article = Article.new 
   end

   def create
     @article = Article.new(article_params)
     if  @article.save
       flash[:notice] = "Article was submitted succsefully"
       redirect_to (@article)
     else
       render :new
     end 
   end

    private 
    def article_params 
       params.require(:article).permit(:title, :description)
    end
end 

ask me for any other files if it helps


Solution

  • The problem should be the "end" word that slip on your new.html.erb file. You are missing the <% %> surrounding the end.

    Remember that all ruby code in a view must be inside of <% %> or <%= %>.