开发者

xml format needed in rails 3.0.1??? answer should be NO

what the heck am I doing wrong.

I changed nothing, but now that it is 2011 this call doesn't work as it used to.

Using Active Resource, I can make the following call:

>> Member.find(:all, :params => {:code => "1stb48024957856464d436e79ad9d7bc0c2d46d5a02"})
GET http://localhost:3000/members.xml?code=1stb48024957856464d436e79ad9d7bc0c2d46d5a02
--> 500 Internal Server Error  (1601 371ms)
ActiveResource::ServerError: Failed with 500 Internal Server Error

As you can see, I get a 500 error. So i go to my server to where i'm making the call.

The code is here in the controller:

def index
  @store = Store.first
  @members = @store.members.find_by_code(params[:code])

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render @members.to_xml } # i also tried :xml => @members but that screws up too the same way.
  end
end

But below is the stack trace. It's doing my head in why this just stopped working.


Started GET "/members.xml?code=1stb48024957856464d436e79ad9d7bc0c2d46d5a02" for 127.0.0.1 at 2011-01-21 13:58:00 -0500
  Processing by MembersController#index as XML
  Parameters: {"code"=>"1stb48024957856464d436e79ad9d7bc0c2d46d5a02"}
  SQL (0.8ms)  SHOW TABLES
  Store Load (0.4ms)  SELECT `stores`.* FROM `stores` LIMIT 1
  Member Load (0.8ms)  SELECT `members`.* FROM `members` WHERE (`members`.store_id = 1) AND (`members`.`code` = '1stb48024957856464d436e79ad9d7bc0c2d46d5a02') LIMIT 1
Completed   in 268ms

ActionView::MissingTemplate (Missing template 

  4
  1stb48024957856464d436e79ad9d7bc0c2d46d5a02
  2010-12-02T20:14:54Z
  3
  70.2
  10
  http://fnd.nu/7
  1
  2010-12-09T15:37:42Z

 with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:xml], :locale=>[:en, :en]} in view paths "/Users/nerb/current_project/fund/app/views", "/Users/nerb/.rvm/gems/ruby-1.9.2-p0/gems/devise-1.1.3/app/views", "/Users/nerb/current_project/fund", "/"):
  app/controllers/members_controller.rb:16:in `block (2 levels) in index'
  app/controllers/members_controller.rb:14:in `index'

Rendered /Users/nerb/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (31.6ms)


Any thoughts are appreciated. I thought xml formats were expempt from render? Jose said as much in this lighthouse ticket, but i can't find what he is talking about.

UPDATE:

Andy that worked as the Server seems to be sending a 200 so thanks, but now i get this error:

Member.find(:all, :params => {:code => "1stb48024957856464d436e79ad9d7bc0c2d46d5a02"})
GET http://localhost:3000/members.xml?code=1stb48024957856464d436e79ad9d7bc0c2d46d5a02
--> 200 OK  (472 399ms)
NoMethodError: undefined method `collect!' for #
    from /Users/nerb/.rvm/gems/ruby-1.8.7-p249/gems/activeresource-2.3.5/lib/active_resource/base.rb:662:in `instantiate_collection'
    from /Users/nerb/.rvm/gems/ruby-1.8.7-p249/gems/activeresource-2.3.5/lib/active_resource/base.rb:639:in `find_every'
    from /Users/nerb/.rvm/gems/ruby-1.8.7-p249/gems/activeresource-2.3.5/lib/active_resource/base.rb:582:in `find'
    from (irb):1

Thoughts? should it just be an array coming back开发者_StackOverflow中文版, even if it's ONE record?


render :xml => @members is the way to go.

Make sure you reload/restart your server after making this change if in production.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜