我正在尝试以ajax形式进行远程搜索,其中用户键入代码,并通过ajax提交,控制器获取代码并查看数据库中的任何内容是否匹配,然后控制器然后适当地返回响应。当我尝试搜索时,我不断获得一个UNKNOW ActionController::UnknownFormat
。
这是我的控制器动作
class TenantsController < ApplicationController
def search
@count = 0
@property = Property.find_by_propertyid(params[:propertyid])
@current_tenant =current_tenant
if @property
toast('success', "#{@property.propertyid}")
@current_tenant.landlord_id = @property.landlord_id
@current_tenant.property_id = @property.id
@current_tenant.save
redirect_to authenticated_tenant_path
else
respond_to do |format|
format.js
end
redirect_to authenticated_tenant_path
end
端
这是我的视图模板表单
<%= form_tag({controller: "tenants", action: "search", remote:true,}, method: "get") do %>
<%= label_tag(:propertyid, "Search for:") %>
<%= text_field_tag(:propertyid) %>
<%= submit_tag("Search") %>
<% end %>
这是路线文件
match '/tenant/search' => "tenants#search",via: [:get, :post]
我有一个带有简单alert('i am here')
这是错误日志
Started GET "/tenants/edit" for 127.0.0.1 at 2015-03-29 21:54:33 -0400
Processing by Tenant::RegistrationsController#edit as JS
Tenant Load (0.8ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."id" = 27 ORDER BY "tenants"."id" ASC LIMIT 1
Tprofile Load (0.2ms) SELECT "tprofiles".* FROM "tprofiles" WHERE "tprofiles"."tenant_id" = 27 LIMIT 1
Rendered tenantprofiles/_edit.html.erb (3.7ms)
Rendered tenants/registrations/edit.html.erb within layouts/dash_tenants (30.2ms)
Rendered layouts/tenants/_dash_side.html.erb (0.7ms)
Rendered layouts/tenants/_dash_header.html.erb (0.5ms)
Completed 200 OK in 88ms (Views: 77.5ms | ActiveRecord: 0.9ms)
Started GET "/tenant/search?utf8=%E2%9C%93&propertyid=a&commit=Search" for 127.0.0.1 at 2015-03-29 21:54:35 -0400
Processing by TenantsController#search as HTML
Parameters: {"utf8"=>"✓", "propertyid"=>"a", "commit"=>"Search"}
Tenant Load (0.2ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."id" = 27 ORDER BY "tenants"."id" ASC LIMIT 1
Property Load (0.4ms) SELECT "properties".* FROM "properties" WHERE "properties"."propertyid" = 'a' LIMIT 1
Completed 406 Not Acceptable in 7ms
ActionController::UnknownFormat - ActionController::UnknownFormat:
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:372:in `retrieve_collector_from_mimes'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:189:in `respond_to'
app/controllers/tenants_controller.rb:38:in `search'
但我甚至没有到达那里。我做错了什么?