我正在完成一个关于 Rails 的教程——但是该教程是用 Rails 2 编写的,并且因为我有 Rails 3,所以我必须将所有内容都转换过来。
我有一个谷歌地图,当你点击它时,你应该会出现一个带有新标记的弹出窗口和一个用于输入数据的表单。当我单击地图时,会出现标记,但没有输入数据的表格。任何帮助将非常感激!
我猜它与ajax有关?当我单击地图上的任意位置尝试输入新数据时,Web 控制台显示 500 内部服务器错误。不知道我哪里错了!
这是“新”操作的控制器代码:
def new
@incident = Incident.new
respond_to do |format|
format.html {
@incident.latitude=params['latitude']
@incident.longitude=params['longitude']
render :partial=>'new', :locals=>{:incident=>@incident}
}
format.xml { render :xml => @incident }
end
end
索引视图:
<h1>Listing incidents</h1>
<%= render(:partial=>"map", :locals=>{:data=>"/incidents.xml",
:full_page=>true, :show_action=>'show', :new_action=>'new'}) %>
和“新”部分:
<h1>New incident</h1>
<% form_for(incident, :update=>'map_info'), :remote => true do |f| %>
<p>
<%= f.label :mountain %> <%= f.text_field :mountain %>
</p>
<%= f.hidden_field :latitude %>
<%= f.hidden_field :longitude %>
<p>
<%= f.label :when %> <%= f.datetime_select :when %>
</p>
<p>
<%= f.label :title %> <%= f.text_field :title %>
</p>
<p>
<%= f.label :description %><br/>
<%= f.text_area :description, :rows=>3 %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
这是堆栈跟踪(当我加载页面时,然后单击地图以获取新事件):
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-09-27 14:35:18
+0100
Served asset /application.js - 304 Not Modified (173ms)
[2012-09-27 14:35:18] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/prototype.js?body=1" for 127.0.0.1 at 2012-09-27 14:35:18 +
0100
Served asset /prototype.js - 304 Not Modified (0ms)
[2012-09-27 14:35:18] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/incidents.xml" for 127.0.0.1 at 2012-09-27 14:35:19 +0100
Processing by IncidentsController#index as XML
←[1m←[35mIncident Load (1.0ms)←[0m SELECT "incidents".* FROM "incidents"
Rendered text template (0.0ms)
Completed 200 OK in 945ms (Views: 184.0ms | ActiveRecord: 1.0ms)
[2012-09-27 14:35:20] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/incidents/new?latitude=42.50990089326676&longitude=-99.4921875" fo
r 127.0.0.1 at 2012-09-27 14:35:43 +0100
Processing by IncidentsController#new as JS
Parameters: {"latitude"=>"42.50990089326676", "longitude"=>"-99.4921875"}
ERROR: compiling _app_views_incidents__new_html_erb___613446974_25808988 RAISED
c:/Ruby193/incidents/app/views/incidents/_new.html.erb:2: syntax error, unexpect
ed ',', expecting keyword_end
'); form_for(incident, :update=>'map_info'), :remote => true do |f|
^
c:/Ruby193/incidents/app/views/incidents/_new.html.erb:23: syntax error, unexpec
ted keyword_ensure, expecting $end
Function body: def _app_views_incidents__new_html_erb___613446974_2580
8988(local_assigns, output_buffer)
_old_virtual_path, @virtual_path = @virtual_path, "incidents/_new";_
old_output_buffer = @output_buffer;incident = local_assigns[:incident];new = loc
al_assigns[:new];;@output_buffer = output_buffer || ActionView::OutputBuffer.new
;@output_buffer.safe_concat('<h1>New incident</h1>
'); form_for(incident, :update=>'map_info'), :remote => true do |f|
@output_buffer.safe_concat(' <p>
');@output_buffer.append= ( f.label :mountain );@output_buffer.safe_concat('
');@output_buffer.append= ( f.text_field :mountain );@output_buffer.safe_concat
('
');@output_buffer.safe_concat(' </p>
');@output_buffer.append= ( f.hidden_field :latitude );@output_buffer.safe_con
cat('
');@output_buffer.safe_concat(' ');@output_buffer.append= ( f.hidden_field :lon
gitude );@output_buffer.safe_concat('
');@output_buffer.safe_concat(' <p>
');@output_buffer.append= ( f.label :when );@output_buffer.safe_concat(' ');
@output_buffer.append= ( f.datetime_select :when );@output_buffer.safe_concat('
');@output_buffer.safe_concat(' </p>
<p>
');@output_buffer.append= ( f.label :title );@output_buffer.safe_concat(' ')
;@output_buffer.append= ( f.text_field :title );@output_buffer.safe_concat('
');@output_buffer.safe_concat(' </p>
<p>
');@output_buffer.append= ( f.label :description );@output_buffer.safe_conca
t('<br/>
');@output_buffer.append= ( f.text_area :description, :rows=>3 );@output_buf
fer.safe_concat('
');@output_buffer.safe_concat(' </p>
<p>
');@output_buffer.append= ( f.submit "Create" );@output_buffer.safe_concat('
');@output_buffer.safe_concat(' </p>
'); end
@output_buffer.to_s
ensure
@virtual_path, @output_buffer = _old_virtual_path, _old_output_buffe
r
end
Backtrace: C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_v
iew/template.rb:297:in `module_eval'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/templat
e.rb:297:in `compile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/templat
e.rb:244:in `block in compile!'
<internal:prelude>:10:in `synchronize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/templat
e.rb:232:in `compile!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/templat
e.rb:144:in `block in render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications.rb:125:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/templat
e.rb:143:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/partial_renderer.rb:265:in `render_partial'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/partial_renderer.rb:238:in `block in render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/abstract_renderer.rb:38:in `block in instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications.rb:123:in `block in instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications/instrumenter.rb:20:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications.rb:123:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/abstract_renderer.rb:38:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/partial_renderer.rb:237:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/renderer.rb:41:in `render_partial'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_view/rendere
r/renderer.rb:15:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/rendering.rb:110:in `_render_template'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/streaming.rb:225:in `_render_template'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/rendering.rb:103:in `render_to_body'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/renderers.rb:28:in `render_to_body'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/compatibility.rb:50:in `render_to_body'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/rendering.rb:88:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/rendering.rb:16:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:40:in `block (2 levels) in render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
ore_ext/benchmark.rb:5:in `block in ms'
C:/Ruby193/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
ore_ext/benchmark.rb:5:in `ms'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:40:in `block in render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:83:in `cleanup_view_runtime'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.4.rc1/lib/active_record/rai
lties/controller_runtime.rb:24:in `cleanup_view_runtime'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:39:in `render'
c:/Ruby193/incidents/app/controllers/incidents_controller.rb:24:in `block (2 lev
els) in new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/mime_responds.rb:196:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/mime_responds.rb:196:in `respond_to'
c:/Ruby193/incidents/app/controllers/incidents_controller.rb:20:in `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/implicit_render.rb:4:in `send_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/base.rb:167:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/rendering.rb:10:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/callbacks.rb:18:in `block in process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:414:in `_run__322942522__process_action__447782570__callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:405:in `__run_callback'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:385:in `_run_process_action_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:81:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/callbacks.rb:17:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/rescue.rb:29:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:30:in `block in process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications.rb:123:in `block in instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications/instrumenter.rb:20:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/n
otifications.rb:123:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/instrumentation.rb:29:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/params_wrapper.rb:206:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.4.rc1/lib/active_record/rai
lties/controller_runtime.rb:18:in `process_action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/base.rb:121:in `process'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/abstract_controller
/rendering.rb:45:in `process'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal.rb:203:in `dispatch'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal/rack_delegation.rb:14:in `dispatch'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_controller/m
etal.rb:246:in `block in action'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/rou
ting/route_set.rb:73:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/rou
ting/route_set.rb:73:in `dispatch'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/rou
ting/route_set.rb:36:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `b
lock in call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `e
ach'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `c
all'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/rou
ting/route_set.rb:600:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/best_standards_support.rb:17:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in
`call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/head.rb:14:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/params_parser.rb:21:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/flash.rb:238:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:2
05:in `context'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:2
00:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/cookies.rb:338:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.4.rc1/lib/active_record/que
ry_cache.rb:64:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.4.rc1/lib/active_record/con
nection_adapters/abstract/connection_pool.rb:473:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/callbacks.rb:28:in `block in call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:405:in `_run__711941801__call__927210605__callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:405:in `__run_callback'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:385:in `_run_call_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
allbacks.rb:81:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/callbacks.rb:27:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/reloader.rb:65:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/remote_ip.rb:31:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/debug_exceptions.rb:16:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/show_exceptions.rb:56:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.4.rc1/lib/rails/rack/logger.rb:
26:in `call_app'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.4.rc1/lib/rails/rack/logger.rb:
16:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/request_id.rb:22:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in
`call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.4.rc1/lib/active_support/c
ache/strategy/local_cache.rb:72:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_dispatch/mid
dleware/static.rb:62:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.4.rc1/lib/rails/engine.rb:479:i
n `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.4.rc1/lib/rails/application.rb:
220:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in
`call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.4.rc1/lib/rails/rack/log_tailer
.rb:17:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in
`service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered incidents/_new.html.erb (169.0ms)
Completed 500 Internal Server Error in 178ms
ActionView::Template::Error (c:/Ruby193/incidents/app/views/incidents/_new.html.
erb:2: syntax error, unexpected ',', expecting keyword_end
'); form_for(incident, :update=>'map_info'), :remote => true do |f|
^
c:/Ruby193/incidents/app/views/incidents/_new.html.erb:23: syntax error, unexpec
ted keyword_ensure, expecting $end):
1: <h1>New incident</h1>
2: <% form_for(incident, :update=>'map_info'), :remote => true do |f| %>
3: <p>
4: <%= f.label :mountain %> <%= f.text_field :mountain %>
5: </p>
app/controllers/incidents_controller.rb:24:in `block (2 levels) in new'
app/controllers/incidents_controller.rb:20:in `new'
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_d
ispatch/middleware/templates/rescues/_trace.erb (5.0ms)
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_d
ispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.4.rc1/lib/action_d
ispatch/middleware/templates/rescues/template_error.erb within rescues/layout (1
38.0ms)