【发布时间】:2011-04-07 08:02:36
【问题描述】:
我编写了一个基本的 Rails 3 应用程序,它在特定 URL 上显示一个表单和一个上传表单。昨天一切正常,但现在我遇到了几个需要修复的问题。我会尽量描述每个问题。我将它们组合在一起的原因是因为我觉得它们都是相关的并且阻止我完成我的任务。
1.无法在开发模式下运行应用程序 由于某些未知原因,我无法让应用程序在开发模式下运行。目前我已经使用开发环境中的设置覆盖了环境中的 production.rb 文件以获取实际的堆栈跟踪。
我已将 RailsEnv 生产设置添加到我在 apache2 中的 VirtualHost 设置中,但似乎没有什么区别。也不会将 ENV 变量设置为生产环境。
2.所有调用的 ArgumentError 无论我打什么电话,都会导致此错误消息。日志文件告诉我以下内容:
在 192.168.33.82 开始 GET "/" 2011 年 4 月 7 日星期四 00:54:48 -0700
ArgumentError(错误的数量 参数(1 代表 0)):
渲染 /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms) 渲染 /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (4.1ms) 渲染 /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb 在救援/布局内 (8.4ms)
这对我来说真的没有任何意义。我不知道出了什么问题。我目前只有一个控制器,如下所示:
class SearchEngineController < ApplicationController
def upload
end
def search
@rows = nil
end
# This function will receive the query string from the search form and perform a search on the
# F.I.S.E index to find any matching results
def query
index = Ferret::Index::Index.new :path => "/public/F.I.S.E", :default_field => 'content'
@rows = Array.New
index.search_each "content|title:#{params[:query]}" do |id,score, title|
@rows << {:id => id, :score => score, :title => title}
end
render :search
end
# This function will receive the file uploaded by the user and process it into the
# F.I.S.E for searching on keywords and synonims
def process
index = Ferret::Index::Index.new :path => "public/F.I.S.E", :default_field => 'content'
file = File.open params[:file], "r"
xml = REXML::Document.new file
filename = params[:file]
title = xml.root.elements['//body/title/text()']
content = xml.root.elements['normalize-space(//body)']
index << { :filename => filename, :title => title, :content => content}
file.close
FileUtils.rm file
end
end
我的应用程序的路由具有以下设置:同样,这都是非常基本的,可能可以做得更好。
Roularta::Application.routes.draw do
# define all the url paths we support
match '/upload' => 'search_engine#upload', :via => :get
match '/process' => 'search_engine#process', :via => :post
# redirect the root of the application to the search page
root :to => 'search_engine#search'
# redirect all incoming requests to the query view of the search engine
match '/:controller(/:action(/:id))' => 'search_engine#search'
end
如果有人能发现问题所在以及此应用程序失败的原因,请告诉我。如果需要,我可以编辑此 awnser 并包含解决此问题可能需要的其他文件。
编辑 通过重命名控制器上的一项功能,我设法走得更远。我将搜索重命名为创建,现在我得到了 HAML 错误。也许我使用了关键字...?
【问题讨论】:
标签: ruby-on-rails ubuntu apache2