I wrote an article the other day stating that I had no idea why someone would call a Helper method from inside a Controller in Rails.
I just found a reason. Here is what I needed to do:
From inside my controller, I wanted to be able to generate some AJAX code that would be sent back to the page. In other words, I needed to generate some HTML (for an AJAX reply) that would be able to make a remote call and the best way to do this is through the link_to_remote() function.
Here is the code I added to my Controller in order to be able to achieve this:
class ConciliationsController < ApplicationController
# for this example you can use either of the lines below and it should work
include ActionView::Helpers::PrototypeHelper
include ActionView::Helpers::JavaScriptHelper
# this method is called by AJAX, which means that I have also
# a cal to link_to_remote in my view
def reconcile
@transaction = Transaction.find(params[:transaction_id])
render :update do |page|
page.replace_html "transaction-item",
link_to_remote('reconcile',
:url => {:action => "reconcile", :transaction_id => @transaction.id} )
end
end
end
Cheers!
Recent comments
17 weeks 6 days ago
17 weeks 6 days ago
18 weeks 1 day ago
18 weeks 3 days ago
19 weeks 10 hours ago
19 weeks 12 hours ago
24 weeks 3 days ago
25 weeks 4 hours ago
25 weeks 5 days ago
26 weeks 4 days ago