perseverance
perseverance

Reputation: 6612

How do you disable needing a template for a respond_to in Ruby on Rails?

I am getting the following error:

ActionView::MissingTemplate (Missing template product/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :haml]}

controller code:

  def create
    product = Product.new(params[:product])
    product.save
  end

The reason why I'm getting this is because I don't have a respond_to block for this action or a template file. It is an create action that I am running via AJAX to create a product. I don't need/want to respond with anything after this is sent to the server. Is there a way to disable this so I don't get these errors? They best way I can think of is to create a respond_to block with format.js and create a _create.js.erb file that is blank but that seems like a hack.

Thanks

Upvotes: 2

Views: 1197

Answers (1)

aNoble
aNoble

Reputation: 7072

Just add

render nothing: true

http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-nothing

Upvotes: 3

Related Questions