Ruby on Rails 3.2
我的视图中有一个AJAX脚本,它在我的控制器中运行我的create方法。一切都运作良好,但我注意到在日志中它正在寻找一个应该的模板。我通常会有重定向或让它做某事,但这次我不想让它做任何事情。
如何跳过或中断模板查找?
我的观点:
$(document).ready(function() {
$.ajax({
type: 'GET',
dataType: 'script',
url: '/track' + '<%= url_for(action: "create") %>'
});
});
我的控制器:
def create
@reseller_name = Reseller.find("#{current_user.reseller_id}").company_name
@track = Track.create(name: "#{current_user.name}", user_id: "#{current_user.id}", reseller_id: "#{current_user.reseller_id}", reseller_name: "#{@reseller_name}")
#This is where I would normally have a render or redirect, I just want it to stop, and not look for a template.
end
我的日志:
(26.8ms) COMMIT
Completed 500 Internal Server Error in 85ms
ActionView::MissingTemplate (Missing template tracks/create, application/create with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmasc
ript", :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :
xls], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/opt/RoR/reseller_connect/app/views"
):
答案 0 :(得分:2)
def create
@reseller_name = Reseller.find("#{current_user.reseller_id}").company_name
@track = Track.create(name: "#{current_user.name}", user_id: "#{current_user.id}", reseller_id: "#{current_user.reseller_id}", reseller_name: "#{@reseller_name}")
render :nothing => true
end