thiagoh
thiagoh

Reputation: 7398

Rails: Template is missing when AJAX and .js.rjs files

I am trying to execute an AJAX routine with rails the code runs normally but the response doesnt..

I get this error

Template is missing

Missing template line_items/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "D:/ruby/depot/app/views" 

I created the create.js.rjs inside line_items directory like the book Agile Web Development says it is to be, but the error insists..

#file line_items_controller.rb

def create
    @cart = current_cart
    product = Product.find(params[:product_id])
    @line_item = add_product(@cart, product.id)

    respond_to do |format|
       if @line_item.save
        format.html { redirect_to store_url }
        format.js 
        format.json { render json: @line_item, status: :created, location: @line_item }
        #...
      end
    end
  end

and inside my create.js.rjs I got this

page.replace_html('cart', render(@cart))

Upvotes: 0

Views: 559

Answers (1)

Vadym Chumel
Vadym Chumel

Reputation: 1776

Rjs is not a valid format anymore I guess. Use js.erb instead. Also manual you're following is outdated since none uses prototype anymore.

Upvotes: 1

Related Questions