Note that there are some explanatory texts on larger screens.

plurals
  1. POrails render_to_string problem
    text
    copied!<p>I`m trying to test my controller with rspec and always get an error. </p> <p>users_controller.rb:</p> <pre><code>def update @user.update_attributes!(params[:user]) redirect_to @user, :status =&gt; 202, :text =&gt; render_to_string(:partial =&gt; "users/show", :type =&gt; "json", :locals =&gt; {:user =&gt; @user}) #notice, that redirect_to was reinitialized and :text is a parameter for response_body end </code></pre> _show.tokamak <pre><code>user { id user.id email user.email username user.username } </code></pre> spec file <pre><code>it "should NOT update user username" do username = @user.username put 'update', :id =&gt; @user.id, :user =&gt; {:username =&gt; username+"abc"}, :format =&gt; :json response.status.should be(202) response.headers["Location"].length.should be &gt; 0 puts response.body @user.reload @user.username.should eq(username) end end </code></pre> <p>So I get an error:</p> <blockquote> <p>Failure/Error: put 'update', :id => @user.id, :user => {:username => username+"abc"}, :format => :json ActionView::Template::Error: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[] # C:/Users/makaroni4/free_frog/ffapi/app/views/users/_show.tokamak:1:in <code>_app_views_users__show_tokamak___509498818 _32151168_368311673' # C:/Users/makaroni4/XXX/XXX/app/controllers/users_controller.rb:22:in </code>update' # ./users_controller_spec.rb:34:in `block (4 levels) in '</p> </blockquote> <p>So may be I call render_to_string method wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload