现在在我的 rails 4 应用程序中,用户提交帖子后我希望应用程序重定向/渲染显示视图,但现在它只是转到创建视图。这是我的帖子控制器:
class PostsController < ApplicationController
def show
@post = Post.find(params[:id]) # show
end
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
private
def post_params
params.require(:post).permit(:Title, :Body) #whatsoever your post has
end
#redirect_to post_path(@post)
if @post.save
redirect_to @post.find(params[:id])
else
render :new
end
end
这是我的路线:
Rails.application.routes.draw do
root :to => "pages#index"
devise_for :users
resources :users
resources :pages
resources :posts
end
谢谢你的帮助。