hi all, in my application, I am trying to send out a notification to users. I can call part_url(@part) from the calling method in the controller BUT when I try to put the value of the parts_url into a notification object, it fails. Here''s the message: ActionController::RoutingError (part_url failed to generate from {:controller=>"parts", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["parts", :id] - are they all satisfied?): (eval):17:in `part_url'' app/models/notification_mailer.rb:11:in `message_to_seller'' app/models/notification_observer.rb:3:in `after_update'' /usr/local/lib/ruby/1.9.1/observer.rb:186:in `block in notify_observers'' /usr/local/lib/ruby/1.9.1/observer.rb:185:in `each'' /usr/local/lib/ruby/1.9.1/observer.rb:185:in `notify_observers'' /usr/local/lib/ruby/gems/1.9.1/gems/after_commit-1.0.8/lib/ after_commit/connection_adapters.rb:12:in `transaction_with_callback'' app/controllers/parts_controller.rb:381:in `block in _send_message_to_seller'' app/controllers/parts_controller.rb:333:in `_send_message_to_seller'' app/controllers/parts_controller.rb:52:in `send_message'' Here''s what the method looks like in myApp/app/controllers/ parts_controller.erb. --------------------------------------------------------------------------------- def send_message @part = Part.find(params[:id]) if ( not params[:type].nil? and params[:type].eql? ''compose_message_to_friend'' ) @page_title = ''Recommendation for "'' + @part.title + ''"'' # composing message to friend _send_message_to_friend(@part) else @page_title = ''Enquiry for "'' + @part.title + ''"'' puts "the url here is " + part_url(@part) <-- the value shows just ok here! # composing message to seller _send_message_to_seller(@part) end end def _send_message_to_seller(part) @notification = Notification.new(params[:notification]) @user_message = params[:notification][:message] params[:notification][:created_by] = ''part enquirer'' params[:notification][:updated_by] = ''part enquirer'' respond_to do |format| if @notification.save puts "We are inside the url is now " + %{Hi, "#{part_url(part)}" onto your browser. } <-- the value shows just ok here! @message = %{Hi, "#{part_url(part)}" onto your browser. } @notification.message = @message @notification.save <!-- ERROR thrown here end end --------------------------------------------------------------------------------- Any ideas? Thank you :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
maybe you can try this: part_url(@part.id) On Tue, Feb 8, 2011 at 8:19 AM, ct9a <anexiole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi all, > > > in my application, I am trying to send out a notification to users. > > I can call part_url(@part) from the calling method in the controller > BUT when I try to put the value of the parts_url into a notification > object, it fails. > Here''s the message: > ActionController::RoutingError (part_url failed to generate from > {:controller=>"parts", :action=>"show"} - you may have ambiguous > routes, or you may need to supply additional parameters for > this route. content_url has the following required parameters: > ["parts", :id] - are they all satisfied?): > (eval):17:in `part_url'' > app/models/notification_mailer.rb:11:in `message_to_seller'' > app/models/notification_observer.rb:3:in `after_update'' > /usr/local/lib/ruby/1.9.1/observer.rb:186:in `block in > notify_observers'' > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `each'' > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `notify_observers'' > /usr/local/lib/ruby/gems/1.9.1/gems/after_commit-1.0.8/lib/ > after_commit/connection_adapters.rb:12:in `transaction_with_callback'' > app/controllers/parts_controller.rb:381:in `block in > _send_message_to_seller'' > app/controllers/parts_controller.rb:333:in `_send_message_to_seller'' > app/controllers/parts_controller.rb:52:in `send_message'' > > > > Here''s what the method looks like in myApp/app/controllers/ > parts_controller.erb. > > > > --------------------------------------------------------------------------------- > def send_message > @part = Part.find(params[:id]) > > if ( not params[:type].nil? and params[:type].eql? > ''compose_message_to_friend'' ) > @page_title = ''Recommendation for "'' + @part.title + ''"'' > > # composing message to friend > _send_message_to_friend(@part) > else > @page_title = ''Enquiry for "'' + @part.title + ''"'' > puts "the url here is " + part_url(@part) <-- the value > shows just ok here! > > # composing message to seller > _send_message_to_seller(@part) > end > end > > > def _send_message_to_seller(part) > @notification = Notification.new(params[:notification]) > > @user_message = params[:notification][:message] > > params[:notification][:created_by] = ''part enquirer'' > params[:notification][:updated_by] = ''part enquirer'' > > respond_to do |format| > if @notification.save > puts "We are inside the url is now " + %{Hi, > "#{part_url(part)}" onto your browser. } <-- the value shows just ok > here! > > @message = %{Hi, "#{part_url(part)}" onto your browser. } > > @notification.message = @message > @notification.save <!-- ERROR thrown here > end > end > > > > --------------------------------------------------------------------------------- > > > Any ideas? Thank you :) > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi, all, I figured out why. I was updating my source codes and i actually put another call for parts_url in my notification_mailer.rb under the model subdirectory. Lesson of the day - never call *_url within your model especially when the object does not belong to the class where the model is being called. hahah @hendra - thanks for your reply but i doubt passing @part.id would work as part_url was expecting an object... On Feb 8, 2:50 pm, Hendra Gunawan <ultimesia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> maybe you can try this: > > part_url(@part.id) > > > > > > > > On Tue, Feb 8, 2011 at 8:19 AM, ct9a <anexi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > hi all, > > > in my application, I am trying to send out a notification to users. > > > I can call part_url(@part) from the calling method in the controller > > BUT when I try to put the value of the parts_url into a notification > > object, it fails. > > Here''s the message: > > ActionController::RoutingError (part_url failed to generate from > > {:controller=>"parts", :action=>"show"} - you may have ambiguous > > routes, or you may need to supply additional parameters for > > this route. content_url has the following required parameters: > > ["parts", :id] - are they all satisfied?): > > (eval):17:in `part_url'' > > app/models/notification_mailer.rb:11:in `message_to_seller'' > > app/models/notification_observer.rb:3:in `after_update'' > > /usr/local/lib/ruby/1.9.1/observer.rb:186:in `block in > > notify_observers'' > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `each'' > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `notify_observers'' > > /usr/local/lib/ruby/gems/1.9.1/gems/after_commit-1.0.8/lib/ > > after_commit/connection_adapters.rb:12:in `transaction_with_callback'' > > app/controllers/parts_controller.rb:381:in `block in > > _send_message_to_seller'' > > app/controllers/parts_controller.rb:333:in `_send_message_to_seller'' > > app/controllers/parts_controller.rb:52:in `send_message'' > > > Here''s what the method looks like in myApp/app/controllers/ > > parts_controller.erb. > > > --------------------------------------------------------------------------- ------ > > def send_message > > @part = Part.find(params[:id]) > > > if ( not params[:type].nil? and params[:type].eql? > > ''compose_message_to_friend'' ) > > @page_title = ''Recommendation for "'' + @part.title + ''"'' > > > # composing message to friend > > _send_message_to_friend(@part) > > else > > @page_title = ''Enquiry for "'' + @part.title + ''"'' > > puts "the url here is " + part_url(@part) <-- the value > > shows just ok here! > > > # composing message to seller > > _send_message_to_seller(@part) > > end > > end > > > def _send_message_to_seller(part) > > @notification = Notification.new(params[:notification]) > > > @user_message = params[:notification][:message] > > > params[:notification][:created_by] = ''part enquirer'' > > params[:notification][:updated_by] = ''part enquirer'' > > > respond_to do |format| > > if @notification.save > > puts "We are inside the url is now " + %{Hi, > > "#{part_url(part)}" onto your browser. } <-- the value shows just ok > > here! > > > @message = %{Hi, "#{part_url(part)}" onto your browser. } > > > -vdJTH0ZjJ4C+oSbvwQOFCMaZJBYrHS8A@public.gmane.org = @message > > -vdJTH0ZjJ4AYObqrr1GBirNAH6kLmebB@public.gmane.org <!-- ERROR thrown here > > end > > end > > > --------------------------------------------------------------------------- ------ > > > Any ideas? Thank you :) > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Congratulations on solving your problem. However, I just want to clarify one thing regarding named routes. (Just to help users reading the thread) What Hendra said isn''t wrong. You can pass anything to part_url and it will be passed to the controller as params[:id]. To make our codes easier to read, the core developers allowed us to pass an object to part_url. Someone correct me if I''m wrong, but I believe passing an object to part_url uses the object''s to_param method which returns the id by default. So part_url(@part) and part_url(@part.id) should return the same string if you didn''t override @part''s to_param method. On Tue, Feb 8, 2011 at 11:57 AM, ct9a <anexiole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, all, > > I figured out why. > I was updating my source codes and i actually put another call for > parts_url in my notification_mailer.rb under the model subdirectory. > > Lesson of the day - never call *_url within your model especially when > the object does not belong to the class where the model is being > called. > > hahah > > > @hendra - thanks for your reply but i doubt passing @part.id would > work as part_url was expecting an object... > > > > On Feb 8, 2:50 pm, Hendra Gunawan <ultimesia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > maybe you can try this: > > > > part_url(@part.id) > > > > > > > > > > > > > > > > On Tue, Feb 8, 2011 at 8:19 AM, ct9a <anexi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > hi all, > > > > > in my application, I am trying to send out a notification to users. > > > > > I can call part_url(@part) from the calling method in the controller > > > BUT when I try to put the value of the parts_url into a notification > > > object, it fails. > > > Here''s the message: > > > ActionController::RoutingError (part_url failed to generate from > > > {:controller=>"parts", :action=>"show"} - you may have ambiguous > > > routes, or you may need to supply additional parameters for > > > this route. content_url has the following required parameters: > > > ["parts", :id] - are they all satisfied?): > > > (eval):17:in `part_url'' > > > app/models/notification_mailer.rb:11:in `message_to_seller'' > > > app/models/notification_observer.rb:3:in `after_update'' > > > /usr/local/lib/ruby/1.9.1/observer.rb:186:in `block in > > > notify_observers'' > > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `each'' > > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `notify_observers'' > > > /usr/local/lib/ruby/gems/1.9.1/gems/after_commit-1.0.8/lib/ > > > after_commit/connection_adapters.rb:12:in `transaction_with_callback'' > > > app/controllers/parts_controller.rb:381:in `block in > > > _send_message_to_seller'' > > > app/controllers/parts_controller.rb:333:in `_send_message_to_seller'' > > > app/controllers/parts_controller.rb:52:in `send_message'' > > > > > Here''s what the method looks like in myApp/app/controllers/ > > > parts_controller.erb. > > > > > > --------------------------------------------------------------------------- > ------ > > > def send_message > > > @part = Part.find(params[:id]) > > > > > if ( not params[:type].nil? and params[:type].eql? > > > ''compose_message_to_friend'' ) > > > @page_title = ''Recommendation for "'' + @part.title + ''"'' > > > > > # composing message to friend > > > _send_message_to_friend(@part) > > > else > > > @page_title = ''Enquiry for "'' + @part.title + ''"'' > > > puts "the url here is " + part_url(@part) <-- the value > > > shows just ok here! > > > > > # composing message to seller > > > _send_message_to_seller(@part) > > > end > > > end > > > > > def _send_message_to_seller(part) > > > @notification = Notification.new(params[:notification]) > > > > > @user_message = params[:notification][:message] > > > > > params[:notification][:created_by] = ''part enquirer'' > > > params[:notification][:updated_by] = ''part enquirer'' > > > > > respond_to do |format| > > > if @notification.save > > > puts "We are inside the url is now " + %{Hi, > > > "#{part_url(part)}" onto your browser. } <-- the value shows just ok > > > here! > > > > > @message = %{Hi, "#{part_url(part)}" onto your browser. } > > > > > @notification.message = @message > > > @notification.save <!-- ERROR thrown here > > > end > > > end > > > > > > --------------------------------------------------------------------------- > ------ > > > > > Any ideas? Thank you :) > > > > > -- > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cool :) Good to hear. In perl, we used to pass the id of objects we want to methods (ie. search) and have a result given back. I know these days, we pass objects instead of primary ids which is cool :) Cheers:D Gordon Yeong On 8 February 2011 17:41, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Congratulations on solving your problem. However, I just want to clarify > one thing regarding named routes. > (Just to help users reading the thread) > > What Hendra said isn''t wrong. You can pass anything to part_url and it > will be passed to the controller as > params[:id]. To make our codes easier to read, the core developers allowed > us to pass an object to part_url. > Someone correct me if I''m wrong, but I believe passing an object to > part_url uses the object''s to_param method which > returns the id by default. So part_url(@part) and part_url(@part.id) > should return the same string if you didn''t > override @part''s to_param method. > > > On Tue, Feb 8, 2011 at 11:57 AM, ct9a <anexiole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> hi, all, >> >> I figured out why. >> I was updating my source codes and i actually put another call for >> parts_url in my notification_mailer.rb under the model subdirectory. >> >> Lesson of the day - never call *_url within your model especially when >> the object does not belong to the class where the model is being >> called. >> >> hahah >> >> >> @hendra - thanks for your reply but i doubt passing @part.id would >> work as part_url was expecting an object... >> >> >> >> On Feb 8, 2:50 pm, Hendra Gunawan <ultimesia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > maybe you can try this: >> > >> > part_url(@part.id) >> > >> > >> > >> > >> > >> > >> > >> > On Tue, Feb 8, 2011 at 8:19 AM, ct9a <anexi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > hi all, >> > >> > > in my application, I am trying to send out a notification to users. >> > >> > > I can call part_url(@part) from the calling method in the controller >> > > BUT when I try to put the value of the parts_url into a notification >> > > object, it fails. >> > > Here''s the message: >> > > ActionController::RoutingError (part_url failed to generate from >> > > {:controller=>"parts", :action=>"show"} - you may have ambiguous >> > > routes, or you may need to supply additional parameters for >> > > this route. content_url has the following required parameters: >> > > ["parts", :id] - are they all satisfied?): >> > > (eval):17:in `part_url'' >> > > app/models/notification_mailer.rb:11:in `message_to_seller'' >> > > app/models/notification_observer.rb:3:in `after_update'' >> > > /usr/local/lib/ruby/1.9.1/observer.rb:186:in `block in >> > > notify_observers'' >> > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `each'' >> > > /usr/local/lib/ruby/1.9.1/observer.rb:185:in `notify_observers'' >> > > /usr/local/lib/ruby/gems/1.9.1/gems/after_commit-1.0.8/lib/ >> > > after_commit/connection_adapters.rb:12:in `transaction_with_callback'' >> > > app/controllers/parts_controller.rb:381:in `block in >> > > _send_message_to_seller'' >> > > app/controllers/parts_controller.rb:333:in `_send_message_to_seller'' >> > > app/controllers/parts_controller.rb:52:in `send_message'' >> > >> > > Here''s what the method looks like in myApp/app/controllers/ >> > > parts_controller.erb. >> > >> > > >> --------------------------------------------------------------------------- >> ------ >> > > def send_message >> > > @part = Part.find(params[:id]) >> > >> > > if ( not params[:type].nil? and params[:type].eql? >> > > ''compose_message_to_friend'' ) >> > > @page_title = ''Recommendation for "'' + @part.title + ''"'' >> > >> > > # composing message to friend >> > > _send_message_to_friend(@part) >> > > else >> > > @page_title = ''Enquiry for "'' + @part.title + ''"'' >> > > puts "the url here is " + part_url(@part) <-- the value >> > > shows just ok here! >> > >> > > # composing message to seller >> > > _send_message_to_seller(@part) >> > > end >> > > end >> > >> > > def _send_message_to_seller(part) >> > > @notification = Notification.new(params[:notification]) >> > >> > > @user_message = params[:notification][:message] >> > >> > > params[:notification][:created_by] = ''part enquirer'' >> > > params[:notification][:updated_by] = ''part enquirer'' >> > >> > > respond_to do |format| >> > > if @notification.save >> > > puts "We are inside the url is now " + %{Hi, >> > > "#{part_url(part)}" onto your browser. } <-- the value shows just ok >> > > here! >> > >> > > @message = %{Hi, "#{part_url(part)}" onto your browser. } >> > >> > > @notification.message = @message >> > > @notification.save <!-- ERROR thrown here >> > > end >> > > end >> > >> > > >> --------------------------------------------------------------------------- >> ------ >> > >> > > Any ideas? Thank you :) >> > >> > > -- >> > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > To unsubscribe from this group, send email to >> > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > For more options, visit this group at >> > >http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.