Forum: Ruby on Rails invoke a controller def from view without clicking any link

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sijo k. (Guest)
on 2009-05-11 11:01
Hi
   I have a controller def like

 def graph_render
    get_flash_chat_objects
      respond_to do |format|
        format.js do
          render :update do |page|
            page[:graph_div].replace_html :partial => "summary_graph"
          end
      end
    end
end

    So clearly this just accept an ajax request and do the above action
This is working But what I would like to know how can I invoke it from
view without clicking a link or like that

Thanks in advance
Sijo
Frederick C. (Guest)
on 2009-05-11 12:43
(Received via mailing list)
On May 11, 8:01 am, Sijo Kg <removed_email_address@domain.invalid> wrote:
>
>     So clearly this just accept an ajax request and do the above action
> This is working But what I would like to know how can I invoke it from
> view without clicking a link or like that
>

Well unless you have a javascript timer on the page that fires off
your ajax request, it's going to have to happen in response to some
event (not necessarily a mouse click, could be page load, mouseover,
keydown etc...)

Fred
Sijo k. (Guest)
on 2009-05-11 12:50
Hi
   In my partial I tried like
<div id"graph_div" onload="somescript();">
</div>

   But this onload not working Since I tried with an alert first Could
you please tell how can I do this?

Sijo
Mukund (Guest)
on 2009-05-12 15:26
(Received via mailing list)
Use prototype functions to handle the onload events.  It is better
than plugging in onload code into your HTML tags.   Look at the online
documentation for examples.   You can use either the dom:loaded event
or the window:onload event.
This topic is locked and can not be replied to.