Hi, I got News model that has_one Asset. Asset belongs_to News. AssetsController has only detroy method, asset is created in NewsController create action. Both resources are in admin namespace. Now I''d like to delete the asset. I tried something like this: <%= link_to ''delete'', admin_news_item_asset_path(@news, @news.asset), :confirm => ''Are you sure?'', :method => :delete %> but I get the following error: undefined method `has_key?'' for #<Asset:0xb6a22798> vendor/rails/activerecord/lib/active_record/attribute_methods.rb: 240:in `method_missing'' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:128:in `send'' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:128:in `method_missing'' (eval):3:in `admin_news_item_asset_path'' ... If I use the following link: <%= link_to ''delete'', admin_news_item_asset_path(@news), :confirm => ''Are you sure?'', :method => :delete %> I don''t get any errors, but I don''t get asset id as well, only news_item_id. I could use this to delete associated asset, but I''d like to make it work as it should. The routes are as follows: map.namespace :admin do |admin| admin.resources :news, :singular => ''news_item'', :member => { :preview => :get } do |news_item| news_item.resource :asset end end I''m using rails 2.0.2. Thanks in advance --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
not 100% sure, but: admin_news_item_asset_path(@news, @news.asset) should be something like: admin_news_item_asset_path(@news, :asset_id => @news.asset) since rails can guess the param name (:id) only for those parts of the path, that are declared in the routes, all others must be named in hash fashion -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
but i''m not sure, if you need that here. why hand over the asset.id, if it''s stored in @news anyway you could simply call the thing for @news and in destroy use @news.asset or in the has_one declaration simply add: has_one :asset, :dependent => destroy and you''ll never have to think about it again... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 21, 11:22 am, Thorsten Mueller <rails-mailing-l...@andreas- s.net> wrote:> not 100% sure, but: > admin_news_item_asset_path(@news, @news.asset) > > should be something like: > admin_news_item_asset_path(@news, :asset_id => @news.asset) > > since rails can guess the param name (:id) only for those > parts of the path, that are declared in the routes, all > others must be named in hash fashion > -- > Posted viahttp://www.ruby-forum.com/.Thanks. It works, but I still think that rails should automatically figure out ID of the second parameter passed. If I run "rake routes", I can see "admin_news_item_asset_path" listed there together with DELETE method... The generated url is "/admin/news/ 23/asset?id=35", but it should be enough for rails to figure out ID of the asset even with url like this "/admin/news/23/asset". --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Em Friday 21 March 2008, szimek escreveu: [...]> The generated url is "/admin/news/ > 23/asset?id=35", but it should be enough for rails to figure out ID of > the asset even with url like this "/admin/news/23/asset".Only if news has_one asset. Otherwise, Rails can''t figure out which of N assets you want to delete. Sorry my poor English. Best regards, -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 21, 12:41 pm, Davi Vidal <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> Em Friday 21 March 2008, szimek escreveu: > [...] > > > The generated url is "/admin/news/ > > 23/asset?id=35", but it should be enough for rails to figure out ID of > > the asset even with url like this "/admin/news/23/asset". > > Only if news has_one asset. Otherwise, Rails can''t figure out which of N > assets you want to delete. > > Sorry my poor English. > > Best regards, > -- > Davi Vidal > -- > E-mail: davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org > MSN : davivi...-uAjRD0nVeow@public.gmane.org > GTalk : davivi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > Skype : davi vidal > YIM : davi_vidal > ICQ : 138815296Thanks, but I have specified the relationship: News has_one :asset, Asset belongs_to :news. BTW. I''m using edge rails 67328 and not 2.0.2 version. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Em Friday 21 March 2008, szimek escreveu:> On Mar 21, 12:41 pm, Davi Vidal <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote: > > Em Friday 21 March 2008, szimek escreveu: > > [...] > > > > > The generated url is "/admin/news/ > > > 23/asset?id=35", but it should be enough for rails to figure out ID of > > > the asset even with url like this "/admin/news/23/asset". > > > > Only if news has_one asset. Otherwise, Rails can''t figure out > > which of N assets you want to delete.[...]> > Thanks, but I have specified the relationship: News has_one :asset, > Asset belongs_to :news. >Sorry. I missed the point here. You''re right. Best regards, -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---