好的,所以我有一个帖子索引,并希望将其链接到我的幻灯片索引,但由于某种原因,我不断收到此错误
No route matches {:controller=>"slides"}
当我与此链接时
<%= link_to 'Show Slides', post_slides_path(@post) %>
如果我在我的帖子编辑查看器中使用上面相同的链接,它似乎工作正常....有什么建议吗?
我基本上想从我的帖子中的表格链接到这个....../posts/:id/slides
路线.RB
resources :posts do
resources :slides
end
后模型
class Post < ActiveRecord::Base
attr_accessible :text, :title
has_many :slides, :dependent => :destroy
def self.search(search)
if search
where('Title Like ?' , "%#{search}%")
else
scoped
end
end
幻灯片模型
class Slide < ActiveRecord::Base
belongs_to :post
发布索引视图
<table id="posts" class="table table-striped table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% @posts.each do |post| %>
<tr>
<td><%= link_to 'Show Slides', post_slides_path(@post) %>
<td><%= link_to 'Edit', :action => :edit, :id => post.id %></td>
<td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %></td>
</tr>
<% end %>
<tbody>
<% end %>
</table>
后控制器
class PostsController < ApplicationController
def new
@post = Post.new
end
def show
@post = Post.find(params[:id])
end
def index
@posts = Post.search(params[:search]).paginate(:per_page => 10, :page => params[:page])
end
def edit
@post = Post.find(params[:id])
end
滑轨控制器
class SlidesController < ApplicationController
def index
@post = Post.find(params[:post_id])
@slides = @post.slides.all
end
def show
@post = Post.find(params[:post_id])
@slide = @post.slides.find(params[:id])
end
def new
@post = Post.find(params[:post_id])
@slide = Slide.new
end
def edit
@post = Post.find(params[:post_id])
@slide = Slide.find(params[:id])
end