我有一个控制器名称帖子.在我/config/routes.rb,我用过这个 -
resources :posts
Run Code Online (Sandbox Code Playgroud)
/app/controllers/posts_controller.rb:
class PostsController < ApplicationController
def new
@post = Post.new
end
def show
@post = Post.find(params[:id])
end
def categoryshow
@post = Post.find(params[:category])
end
def index
@posts = Post.all
end
def create
@post = Post.new(params[:post])
if @post.save
flash.now[:success] = "Your Post Successful"
redirect_to @post
else
render 'new'
end
end
end
Run Code Online (Sandbox Code Playgroud)
我是铁路新手,我经常对路线感到困惑.我有另一个static_pages控制器.在那里有一个home.html.erb文件.
我想做的是致电 -
def categoryshow
@post = Post.find(params[:category])
end
Run Code Online (Sandbox Code Playgroud)
来自的帖子控制器的'categoryshow'方法 /app/views/static_pages/home.html.erb
我该如何管理?如果我使用'posts_path',它将转到索引操作而不是categoryshow操作.
#我通读了这个链接并尝试了一些东西.这是我面临的问题:
当我在config/routes.rb中尝试这个时
resources :posts do
collection do
get 'categoryshow'
end …Run Code Online (Sandbox Code Playgroud) 我计划建立自己的网站并尽快启动.我正在使用Rails框架进行所有编码.我知道我的网站样式的Bootstrap.
但是,我过去已经在其他网站上使用过Bootstrap.请提出一些其他选择.
谢谢 - 希德