Hi all,
I wonder if it is somehow possible to execture or redirect to a
controller function from RJS?
Right now I do:
def foo()
render :partial => ''executeagain''
end
_executeagain.rhtml
<script>
new Ajax.Updater(''elmntID'', ''/test/foo/'',
{evalScripts:true});
</script>
This will loop I know :)
How can I achieve the same result but without using a partial??
Regards,
Henrik
--
Posted via http://www.ruby-forum.com/.
page.redirect_to :action => ''whatever'' -- Posted via http://www.ruby-forum.com/.
Guest wrote:> page.redirect_to :action => ''whatever''Great! And how would you send in parameters with that? page.redirect_to :action => ''whatever'',para1, para2 ,or? Thanks -- Posted via http://www.ruby-forum.com/.
Guest wrote:> page.redirect_to :action => ''whatever''BTW that did not work! It sends me to another page which I don''t want. I just want to run a controller function and stay on the current page... -- Posted via http://www.ruby-forum.com/.
new Ajax.Request(''<%= url_for(:action => "/test/foo",
:what => "ever")
%>'',
{asynchronous:true, evalScripts:true});
--
Posted via http://www.ruby-forum.com/.
Mick Sharpe wrote:> new Ajax.Request(''<%= url_for(:action => "/test/foo", :what => "ever") > %>'', > {asynchronous:true, evalScripts:true});I really don''t get it. If I have (inline RJS for simplicity) can I do this? render :update do |page| new Ajax.Request(''<%= url_for(:action => "/test/foo", :what => "ever") %>'', {asynchronous:true, evalScripts:true}); end Looks error prone :) Thanks Henrik -- Posted via http://www.ruby-forum.com/.
Ajax.Request will trigger a controller action - you simply need to decide when to call it - either as inline code in which case it will be executed when the page is rendered, or in response to some event, eg onClick=''new Ajax.Request...'' Henrik Zagerholm wrote:> Mick Sharpe wrote: >> new Ajax.Request(''<%= url_for(:action => "/test/foo", :what => "ever") >> %>'', >> {asynchronous:true, evalScripts:true}); > > I really don''t get it. > > If I have (inline RJS for simplicity) can I do this? > render :update do |page| > new Ajax.Request(''<%= url_for(:action => "/test/foo", :what => > "ever") > %>'', {asynchronous:true, evalScripts:true}); > end > > Looks error prone :) > > Thanks > Henrik-- Posted via http://www.ruby-forum.com/.
In fact you just need to use the
[url=http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000420]remote_function
helper. If you omit the :update parameter, it generates an Ajax:Request
call instead of AjaxUpdater - eg:
<element onClick="<%= remote_function(:url => {:action => :foo,
:what =>
''ever''}) >">
--
Posted via http://www.ruby-forum.com/.
Mick Sharpe wrote:> Ajax.Request will trigger a controller action - you simply need to > decide when to call it - either as inline code in which case it will be > executed when the page is rendered, or in response to some event, eg > onClick=''new Ajax.Request...''Yes, I understand that, as I usually use it in partials for executing controller functions. My question is though how to call it from within a RJS template or within inline RJS code? What would the syntax be? Is it possible at all or do I have to render a partial to be able to use the Ajax.request call?? Thanks for your help Henrik -- Posted via http://www.ruby-forum.com/.
try something like this:
<!-- call foo/bar every second -->
<%= periodically_call_remote( { :url => { :controller =>
"foo", :action =>
"bar" }, :frequency => 1 } ) %>
class FooController < ApplicationController
def bar
# do you thing here
render :nothing => true if request.xhr?
end
end
On 4/27/06, Henrik Zagerholm <henke@mac.se> wrote:>
>
> Mick Sharpe wrote:
> > Ajax.Request will trigger a controller action - you simply need to
> > decide when to call it - either as inline code in which case it will
be
> > executed when the page is rendered, or in response to some event, eg
> > onClick=''new Ajax.Request...''
>
> Yes, I understand that, as I usually use it in partials for executing
> controller functions.
>
> My question is though how to call it from within a RJS template or
> within inline RJS code?
>
> What would the syntax be?
> Is it possible at all or do I have to render a partial to be able to use
> the Ajax.request call??
>
> Thanks for your help
> Henrik
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060427/de689edd/attachment.html
I guess you would use the << operator to output raw JavaScript to the
page - something like:
render :update do |page|
page << "new Ajax.Request(''#{url_for(:action =>
"/test/foo", :what =>
"ever")}'', {asynchronous:true, evalScripts:true});"
end
Sorry - I haven''t played around with RJS templates yet - embedding RJS
calls in partials has given me what I need.
--
Posted via http://www.ruby-forum.com/.
...or even:
render :update do |page|
page << remote_function(:url => {:action => :foo, :what =>
"ever"})
end
--
Posted via http://www.ruby-forum.com/.
Mick Sharpe wrote:> ...or even: > > render :update do |page| > page << remote_function(:url => {:action => :foo, :what => "ever"}) > endThat did the trick! I first got some weird results but thats because I hade the :update option on the initial link_to_remote. :) Thanks for all your help! :) Cheers, Henrik -- Posted via http://www.ruby-forum.com/.