我遇到了一个非常奇怪的错误。我已经安装了“Blogit”并试图添加一些零碎的东西。当我提交新条目时,我遇到了一个奇怪的错误:
Template is missing
Missing template blogit/posts/create, blogit/application/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: *
"/Users/James/Documents/Websites/Backpack Bug/app/views" * "/Users/James/.rvm/gems/ruby-
1.9.3-p0/gems/blogit-0.4.8/app/views" * "/Users/James/.rvm/gems/ruby-1.9.3-
p0/gems/kaminari-0.14.1/app/views" * "/Users/James/.rvm/gems/ruby-1.9.3-p0/gems/devise-
2.1.2/app/views"
我觉得这与我的路由有关。这是routes.rb
appname::Application.routes.draw do
root :to => 'locations#index'
devise_for :users
resources :locations do
collection do
get 'location'
end
end
mount Blogit::Engine => "/blog", :as => "blog"
end
这是帖子控制器:
module Blogit
class PostsController < ApplicationController
unless blogit_conf.include_admin_actions
before_filter :raise_404, except: [:index, :show, :tagged]
end
blogit_authenticate(except: [:index, :show, :tagged])
blogit_cacher(:index, :show, :tagged)
blogit_sweeper(:create, :update, :destroy)
def index
respond_to do |format|
format.xml {
@posts = Post.order('created_at DESC')
}
format.html {
@posts = Post.for_index(params[:page])
}
format.rss {
@posts = Post.order('created_at DESC')
}
end
end
def show
@post = Post.find(params[:id])
@comment = @post.comments.new
end
def tagged
@posts = Post.for_index(params[:page]).tagged_with(params[:tag])
render :index
end
def location
@georesult = Geocoder.search(params[:location])
respond_to do |format|
format.html {render :layout=>false}# venues.html.erb
end
end
def new
@post = current_blogger.blog_posts.new(params[:post])
@location = @post.locations.build
end
def edit
@post = current_blogger.blog_posts.find(params[:id])
@location = @post.locations.new
end
def create
@post = current_blogger.blog_posts.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to @post, :method => :get, notice: 'Blog post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
def update
@post = current_blogger.blog_posts.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to @post, notice: 'Blog post was successfully updated.'
else
render action: "edit"
end
end
def destroy
@post = current_blogger.blog_posts.find(params[:id])
@post.destroy
redirect_to posts_url, notice: "Blog post was successfully destroyed."
end
private
def raise_404
# Don't include admin actions if include_admin_actions is false
render file: "#{Rails.root}/public/404.html", status: :not_found, layout: false
end
end
end
到目前为止,我已经从源头改变了,我基本上创建了一个多部分表单,它允许搜索位置并将它们提交到同一帖子操作中的位置表。不确定这是否与它有关。我可以发布所有这些代码,但它非常冗长。如果您认为这也有用,请告诉我。
非常感谢您的帮助!坦率地说,我很难过。
詹姆斯
答案 0 :(得分:1)
只是预感:看看你的location
动作是否被调用。我刚刚遇到了一个稍微不同的错误,即在我的控制器中对redirect_to
的任何调用导致我在同一个控制器中调用location
方法。 (在raise
方法的开头加location
会很快让您知道。)
我没有尝试调查确切的原因,但重命名我的location
操作解决了这个问题(显然,这需要更改引用该端点的任何其他代码,例如我的JavaScript中的AJAX请求)。毫无疑问,Rails魔术。