Reputation: 1753
My first project on ruby on rails. I get this error
My print.html.erb is a static page.It has a link <a href="posts/index">Show</a>
And the print page is the index page in my case i.e localhost:3000 opens the print page.
This is my index.html.erb page(this is the linked page)
<h1>Listing posts</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.text %></td>
</tr>
<% end %>
</table>
This is my controller
class PostsController < ApplicationController
def index
@posts = Post.all
end
def new
end
def create
@post = Post.new(post_params)
@post.save
redirect_to @post
end
def post_params
params.require(:post).permit(:title, :text)
end
def show
@post = Post.find(params[:id])
end
def print
end
end
This is my routes file
Watermark::Application.routes.draw do
resources :posts
root "posts#print"
post 'posts/index' => 'posts#index'
post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end
I guess the problem is in the routes file.
Upvotes: 0
Views: 495
Reputation: 239521
Your routes contain some bogus additions. You shouldn't have added
post 'posts/index' => 'posts#index'
That's only going to conflict with existing routes. You should remove it.
resources :posts
is all you need to generate the seven default RESTful routes in Rails, including index
, which should simply by at /posts
, not /posts/index
.
You should also remove the two catch-all routes, they're not useful anymore. It seems likely that you're working from a pretty dated tutorial.
Upvotes: 1