Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problem executing simple model#to_json

#4015

I'm trying create and run a simple ("hello world") app on Rails 3 pre (and Ruby 1.9.1, under RVM). After installation succeed properly, I executed the follow command sequence:

$ rails ror3test $ cd ror3test $ rails generate scaffold user name:string $ rake db:migrate $ rails server

Until here, all it's ok. So, I added the following line on index action:


format.json { render :json => @users.to_json }

This is ok too, but if I call to_json method with any argument, like:


format.json { render :json => @users.to_json(:methods => :caps) }

or


format.json { render :json => @users.to_json(:only => [:name] }

the following error occur:


TypeError in UsersController#index
wrong argument type Hash (expected Data)

A more detailed error information is attached.

Reported by Líus Fontenelle · February 21st, 2010 @ 12:07 AM

State: invalid
Milestone: none
Assigned to: Rohit Arondekar Rohit Arondekar
Importance: Low

Activity

  1. David Trasbo
    David Trasbo
    • Assigned user set to Ryan Bigg

    I was unable to duplicate this issue on master:

    ➜  ticket_4015 script/rails g model user name:string
    ➜  ticket_4015 rake db:migrate
    (in /Users/dtrasbo/code/rails/railties/tmp/ticket_4015)
    ➜  ticket_4015 script/rails g controller users index
    ➜  ticket_4015 script/rails c
    Loading development environment (Rails 3.0.0.beta4)
    ruby-1.9.2-preview3 > User.create(:name => 'David Trasbo')
     => #<User id: 1, name: "John Smith", ...> 
    ruby-1.9.2-preview3 > User.create(:name => 'Marc Hejner')
     => #<User id: 2, name: "David Trasbo", ...>
    
    class UsersController < ApplicationController
      def index
        @users = User.all
        respond_to do |format|
          format.json { render :json => @users.to_json(:only => :name) }
        end
      end
    end
    

    Response body for http://localhost:3000/users.json:

    [{"user":{"name":"John Smith"}},{"user":{"name":"David Trasbo"}}]
    

    This ticket can be closed.

    July 1st, 2010 @ 09:54 PM

  2. David Trasbo
    David Trasbo

    Gah, you'll probably notice I tried to change some names above, but looked over a couple of places.

    July 1st, 2010 @ 09:57 PM

  3. David Trasbo
    David Trasbo
    • Assigned user changed from Ryan Bigg to Rohit Arondekar

    Closable, see above.

    September 9th, 2010 @ 01:22 PM

  4. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid
    • Importance changed from to Low

    September 9th, 2010 @ 01:45 PM