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