Problem updating rspec using rails 3

I ran into a problem with rspec and controllers

I describe the update action, so for this I call the following code:

put :update, :id => "1", :ntp => {:name=>'myservah'}

My controller has the following code:

def update
 if @ntp.update_attributes(params[:ntp])
  flash.now[:notice] = "Successfully updated ntp."
 else
  flash.now[:error] = ((errors_to_a(@ntp)*'.<br />')+'.')
 end
 render :partial => 'update'
end

And I get the following error:

Error / Error: put: update ,: id => "1",: ntp => {: name => 'myservah'} There is no partial ntps / update using {: handlers => [: erb ,: rjs ,: builder ,: rhtml ,: rxml],: formats => [: html],: locale => [: en ,: en]} to see the path "#"

My question is: should I say which handler I have? Today my part is called "_update.js.erb".

BTW, my code works, I display the version of the update "js", since I just run some scripts

+3
1

Rails , HTTP ( ), :format .

, Rails :html.

, :html, , Rails _update.html.erb. :

  • , html.

    # emulate a js request
    put :update, :id => "1", :ntp => {:name=>'myservah'}, :format => :js
    

    AJAX, , xhr

    # emulate an XHR request
    xhr :put, :update, :id => "1", :ntp => {:name=>'myservah'}, :format => :js
    
  • 406 , js. render :partial => 'update'

    respond_to do |format|
      format.js  { render :partial => 'update' }
      format.any { head 406 }
    end
    
+13

Source: https://habr.com/ru/post/1767902/


All Articles