Question

Ruby on Rails 3.2

I have a AJAX script in my view that runs my create method in my controller. All is working well but I noticed in the log it was looking for a template as it should. I normally would have a redirect or have it do something when but this time I don't want it to do anything.

How do you skip or break the template lookup?

My view:

$(document).ready(function() {
$.ajax({
type: 'GET',
dataType: 'script',
url: '/track' + '<%= url_for(action: "create") %>'
});
});

My controller:

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

My log:

(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"
):
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top