我在使用 Rails 项目时遇到问题。当我按下刷新按钮时,服务器会打印出以下消息:
2012 年 6 月 7 日星期四 22:54:19 -0700 开始为 127.0.0.1 获取“/assets?action=select_refresh&controller=home&id=1”
ActionController::RoutingError (没有路由匹配 [GET] "/assets"): config/initializers/quiet_assets.rb:7:in `call'
渲染 /Library/Ruby/Gems/1.8/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb 在 rescues/la yout (1.2ms)
这是我的代码:
hom_controller.rb
class HomeController < ApplicationController
def index
end
def select_refresh
print("debug")
@specs = Specialization.find(params[:id])
if @specs.update_attributes(params[:specialization])
printnamessid = "printnames" + @specs.id.to_s
render :update do |page|
page[printnamessid].replace :partial => "printnames", :locals => {:s => @specs}
end
else
print("do nothing")
end
end
end
规范.html.erb
<h1>Specializations</h1>
<div id="somediv">
<table width="600" border="2" cellpadding="2" cellspacing="2" align="center">
<tr>
<td width="280">Specialization Name</td>
<td width="50">Application count</td>
<td width="100">Applicant Names</td> <!--table in here-->
<td width="70">Refresh</td>
</tr>
<% Specialization.all.each do |s| %>
<tr>
<td><%= s.name %></td>
<td><%= render :partial => "printcount", :locals => {:s => s} %></td>
<td><%= render :partial => "printnames", :locals => {:s => s} %></td>
<td><%= link_to "Refresh", {:action => "select_refresh", :id => s }, :remote => true %></td>
</tr>
<% end %>
_printnames.html.erb
<div id="printnames<%= s.id%>">
<table width="100" border="2" cellpadding="2" cellspacing="2" align="center">
<% s.applicant.each do |a| %>
<tr>
<td><%= a.firstname %></td>
</tr>
<% end %>
</table>
</div>
你知道有什么问题吗?我用谷歌搜索了一下,但我发现的只是以前版本的 Rails 有问题吗?我使用的是 3.2.5 版。
您是否知道将打印行放入终端或从函数打印警报(如 js)的简单方法?