This project is archived and is in readonly mode.
ActiveResource Failed With Rails 2.2.1
Reported by Joël AZEMAR | November 24th, 2008 @ 10:21 AM
When Rails try to generate <% form_for(@product) do |f| %> for an ActiveResource::Base Product, it's failed like that : product_url failed to generate from {:action=>"show" ... and with move to 2.1.2 and restart mongrel, it's work well.
config/routes.rb
ActionController::Routing::Routes.draw do |map| map.resources :products ... end
Full error message :
Processing ProductsController#new (for 127.0.0.1 at 2008-11-18 14:22:16) [GET] [4;36;1mSQL (0.2ms)[0m [0;1mSET NAMES 'latin1'[0m [4;35;1mSQL (0.1ms)[0m [0mSET SQL_AUTO_IS_NULL=0[0m [4;36;1mSQL (0.1ms)[0m [0;1mSET NAMES 'latin1'[0m [4;35;1mSQL (0.1ms)[0m [0mSET SQL_AUTO_IS_NULL=0[0m Rendering template within layouts/products Rendering products/new
ActionView::TemplateError (product_url failed to generate from {:action=>"show", :id=>#<Product:0x24af1e4 @prefix_options={}, @attributes={}>, :controller=>"products"}, expected: {:action=>"show", :controller=>"products"}, diff: {:id=>#<Product:0x24af1e4 @prefix_options={}, @attributes={}>}) on line #3 of app/views/products/new.html.erb: 1:
New product
2: 3: <% form_for(@product) do |f| %> 4: <%= f.error_messages %> 5: 6:
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/routing/route_set.rb:376:in `raise_named_route_error'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/routing/route_set.rb:340:in `generate'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/url_rewriter.rb:208:in `rewrite_path'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/url_rewriter.rb:187:in `rewrite_url'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/url_rewriter.rb:165:in `rewrite'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:626:in `url_for'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/url_helper.rb:85:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/url_helper.rb:85:in `url_for'
(eval):15:in `product_path'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/polymorphic_routes.rb:111:in `__send__'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/polymorphic_routes.rb:111:in `polymorphic_url'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/polymorphic_routes.rb:118:in `polymorphic_path'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/form_helper.rb:269:in `apply_form_for_options!'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/form_helper.rb:248:in `form_for'
app/views/products/new.html.erb:3
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/renderable.rb:37:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/renderable.rb:37:in `render'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/template.rb:73:in `render_template'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/base.rb:251:in `render'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/base.rb:361:in `_render_with_layout'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_view/base.rb:249:in `render'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:1174:in `render_for_file'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:905:in `render_without_benchmark'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/benchmarking.rb:51:in `render'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.1/lib/active_support/core_ext/benchmark.rb:8:in `realtime'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/benchmarking.rb:51:in `render'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:135:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:135:in `custom'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:164:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:164:in `respond'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:158:in `each'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:158:in `respond'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/mime_responds.rb:107:in `respond_to'
app/controllers/products_controller.rb:29:in `new'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:1253:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/filters.rb:617:in `call_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.1/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.1/lib/active_record/query_cache.rb:8:in `cache'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:524:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:524:in `process_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/session_management.rb:134:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/base.rb:392:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:183:in `handle_request'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:123:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:122:in `synchronize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:122:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/dispatcher.rb:39:in `dispatch'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/usr/bin/mongrel_rails:19:in `load'
/usr/bin/mongrel_rails:19
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/templates/rescues/trace (46.5ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/templates/rescues/request_and_response (0.9ms) Rendering /Library/Ruby/Gems/1.8/gems/actionpack-2.2.1/lib/action_controller/templates/rescues/layout.erb (internal_server_error)
Comments and changes to this ticket
-
Joël AZEMAR November 24th, 2008 @ 10:26 AM
- Tag changed from 2.2.rc1, activeresource, form_for, routes to 2.2.rc1, 2.2.rc2, activeresource, form_for, routes
Same error with Rails 2.2.2
-
Michael Koziarski November 24th, 2008 @ 10:35 AM
Have you overridden to_param on your product class?
I can't reproduce this locally, the best bet is probably for you to start a tiny rails application which demonstrates this problem.
-
Joël AZEMAR November 24th, 2008 @ 10:47 AM
$ rails activeresource_fail_sample $ cd activeresource_fail_sample $ ./script/generate scaffold Product title:string content:text
Change ProductModel like that : class Product < ActiveResource::Base self.site = "http://application.localhost.com:3000" end
start
$ mongrel_rails mongrel::start -e development -p 3000
and fail ...
$ ./script/about : $ ./script/about About your application's environment Ruby version 1.8.6 (universal-darwin9.0) RubyGems version 1.3.1 Rails version 2.2.2 Active Record version 2.2.2 Action Pack version 2.2.2 Active Resource version 2.2.2 Action Mailer version 2.2.2 Active Support version 2.2.2 Application root /.../activeresource_fail_sample Environment development Database adapter sqlite3 Database schema version 20081124104024
-
chrispanda November 24th, 2008 @ 12:13 PM
I'm seeing the same problem - I have two almost identical models controllers and views - one throws the error, the other doesn't. If I manage to narrow it down I'll let you know
-
Michael Koziarski November 24th, 2008 @ 01:30 PM
- Milestone cleared.
- Assigned user set to Michael Koziarski
-
David Currin November 26th, 2008 @ 08:57 AM
I've come across the same problem here I think. Written about it already in this rails forum post. And yes I've overridden to_param with:
def to_param "#{id}-#{permalink}" unless id.nil? end
-
Michael Koziarski November 26th, 2008 @ 10:54 AM
OK, this defintely looks like a regression, and we'll get it fixed in the next point release.
-
Michael Koziarski December 1st, 2008 @ 08:10 PM
OK, so the issue here is simply this:
>> Product.new.new_record? => nil
Previously routes were a little more understanding, but no longer.
To fix this for active resource you'll need to submit a patch implementing new_record? for ActiveResource and then everything should be fine.
-
Emilio Tagua December 2nd, 2008 @ 02:22 PM
The problem can be solved just by aliasing the existing method new? to new_record?
I did the patch for both edge and 2.2, but the diff is exactly the same, the file doesn't have any change, so it can be applied to master and 2-2-stable.
-
Michael Koziarski December 2nd, 2008 @ 02:28 PM
- State changed from new to resolved
Cheers, applied and pushed.
This will be fixed in the next point release.
-
Karl Shea - Limited December 11th, 2008 @ 09:50 PM
I'm still seeing this error using the diff above in activeresource-2.2.2. Was there more fixed than just the new_record alias?
-
Michael Koziarski December 12th, 2008 @ 03:06 PM
Are you having this error with form_for(@project) or is it some other call entirely? Routes is now a little pickier about nil values for mandatory keys, you may be hitting those.
Please attach the routes declaration and form tag that you're using so we can see if there's another issue hiding in there.
-
Karl Shea - Limited December 12th, 2008 @ 09:17 PM
I'm using resource_controller as well, but I don't think that's the issue, because this works:
@@@<% for company in @companies %>
<td><%= link_to 'Show', object_url(company) %></td>
But this (with a new object in @company) doesn't:
@@@<% form_for(:company, :url => object_url(@company)) do |f| %>@@@
And it still breaks when I put in company_url.
This is the relevant route:
@@@map.resources :companies do |company| company.resources :contacts company.resources :projects end@@@
All of the actions except when passing in a newly-created object work.
-
Karl Shea - Limited December 12th, 2008 @ 09:19 PM
A preview button would be nice.
Works:
@@@ <% for company in @companies %>
<% end -%> @@@Breaks with new object:
@@@ <% form_for(:company, :url => object_url(@company)) do |f| %> @@@
Route:
@@@ map.resources :companies do |company| company.resources :contacts company.resources :projects end @@@
<%= link_to 'Show', object_url(company) %> -
Karl Shea - Limited December 12th, 2008 @ 09:48 PM
Well, I did make it work with this:
<% form_for(:company, :url => new_object_url) do |f| %>
So I guess that will work, but it still seems odd the other way doesn't work.
-
Karl Shea - Limited December 12th, 2008 @ 09:52 PM
Spoke too soon, that's actually generating the wrong url. (new action instead of create action)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>