class Order < ActiveRecord::Base
def paypal_url(return_url, notify_url)
# ... Do stuff
self.update_attribute(:payment_in_process, true)
# Do more stuff...
end
When I visit the view, the model gets its attribute updated. I do not
want this. I only want the attribute updated if the link is clicked.
class Order < ActiveRecord::Base
def paypal_url(return_url, notify_url)
# ... Do stuff
self.update_attribute(:payment_in_process, true)
# Do more stuff...
end
When I visit the view, the model gets its attribute updated. I do not
want this. I only want the attribute updated if the link is clicked.
You call the method in the view, thus the method is run. Nothing more,
nothing less.
class Order < ActiveRecord::Base
def paypal_url(return_url, notify_url)
# ... Do stuff
self.update_attribute(:payment_in_process, true)
# Do more stuff...
end
When I visit the view, the model gets its attribute updated. I do not
want this. I only want the attribute updated if the link is clicked.
You call the method in the view, thus the method is run. Nothing more,
nothing less.
Nanaya, what can I do to only update the attribute when the link is
clicked?
class Order < ActiveRecord::Base
def paypal_url(return_url, notify_url)
# ... Do stuff
self.update_attribute(:payment_in_process, true)
# Do more stuff...
end
When I visit the view, the model gets its attribute updated. I do not
want this. I only want the attribute updated if the link is clicked.
Know how to accomplish this?
Separate out the code that generates the url from the code that
updates the database. Then run the update in the action that is
called when the link is clicked.
want this. I only want the attribute updated if the link is clicked.
follows the URL generated by the method.
Well that is what you need to fix. If you need to do something to the
database then you need to call an action in your application that does
whatever it is you want to do. If necessary you can then redirect to
your external url.
Are you a beginner with Rails? If so then I suggest that before going
further you work right through a good tutorial such as railstutorial.org (which is free to use online), that will show you
the basics of Rails.
class Order < ActiveRecord::Base
def paypal_url(return_url, notify_url)
# ... Do stuff
self.update_attribute(:payment_in_process, true)
# Do more stuff...
end
When I visit the view, the model gets its attribute updated. I do not
want this. I only want the attribute updated if the link is clicked.
Know how to accomplish this?
Separate out the code that generates the url from the code that
updates the database. Then run the update in the action that is
called when the link is clicked.
Colin
Colin, there’s no action called when the link is clicked, it just
follows the URL generated by the method.
Tried separating the URL generator and creating an action but it turns
out to be the same…
want this. I only want the attribute updated if the link is clicked.
follows the URL generated by the method.
Well that is what you need to fix. If you need to do something to the
database then you need to call an action in your application that does
whatever it is you want to do. If necessary you can then redirect to
your external url.
Are you a beginner with Rails? If so then I suggest that before going
further you work right through a good tutorial such as railstutorial.org (which is free to use online), that will show you
the basics of Rails.
Colin
Managed to solve this a while ago
I created an action for the link which generates and follows the link,
then when it gets back from it (PayPal), it updates the database.
post ‘orders/:id/pay’, to: ‘orders#start_payment_process’, as:
‘start_payment_process’
<%= link_to "Pagar en PayPal", start_payment_process_path, class: