1

我遇到了一个非常奇怪的错误。我已经安装了“ 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

到目前为止,我从源代码所做的所有更改是,我基本上创建了一个多部分表单,它允许搜索位置并将它们提交到同一发布操作中的位置表。不确定这是否与它有关。我可以发布所有这些代码,但它很长。如果您认为这也有用,请告诉我。

非常感谢您的帮助!坦率地说,我很难过。

詹姆士

4

1 回答 1

1

只是一个预感:看看你的location动作是否被调用。我刚刚遇到了一个稍微不同的错误,我的控制器中的任何调用redirect_to都导致我location在同一个控制器中的方法被调用。(在方法raise的开头加上alocation会很快让你知道。)

我没有尝试调查究竟为什么会发生这种情况,但是重命名我的location操作解决了这个问题(显然,这需要更改引用该端点的任何其他代码,例如我的 JavaScript 中的 AJAX 请求)。毫无疑问,Rails 的魔力。

于 2012-12-06T03:41:42.983 回答