I followed a rails tutorial here that has you create a simple blog as an introduction to rails. Now, I'd like to add another page, but I am having some trouble.
So, I have a page that lists all the blog articles located in apps\view\articles\index.html.erb. The code looks like this:
<table>
<tr>
<th>Title</th>
<th>Preview</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text[0,20] %></td>
<td><%= link_to 'Read more...', article_path(article) %></td>
</tr>
<% end %>
</table>
Now, I want to add a link on that page called "Backend" which is an exact duplicate of the page in the code above except it has "Backend" as the header (I will add different functionalities separately to that page later).
-
Above the table in index.html.erb, I wrote:
- In app\views\articles, I created a backend.html.erb file that is an exact duplicate of the index.html.erb file.
3.In app\helpers, I created a backend_helper.rb with the following code:
module BackendHelper
end
4.In app\controllers, I created a duplicate of the Articles controller in the tutorial, except I changed the class to:
class BackendController < ApplicationController
5.And in my routes.rb file, I added a get for backend:
root 'welcome#index'
resources :articles do
root 'articles#index'
end
resources :articles do
resources :comments
end
get 'backend', to: 'backend#index'
Problem:
Now, when I click on the link,I get the following error:
Missing template backend/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "C:/tutorialpath/app/views"
I read about a similar problem here, but it seems like the answer was to create a new html.erb file in the app/views folder (for this project, it is in apps/views/articles) which I did. Does anyone have any other suggestions or see what I am doing wrong?
Aucun commentaire:
Enregistrer un commentaire