Erwin
2010-Aug-17 16:52 UTC
[rails 3] how to write an Ajax call w the new unobtrusive js ?
I have current a js function call I would like to transform into an
Ajax request
= check_box_tag "selection", "1", false, {:id =>
user.id, :onclick =>
"showHideMenuItem(this);"}
I found a lot of examples on link_to , but none on a checkbox .. I
know I have to add :remote => true somewhere, but that''s all I
know ..
please, any help or tip will be welcome !
thanks a lot for your links...
erwin
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
The rails.js UJS file appears to handle only links/anchors or forms.
I went through a "I want to do this with UJS" about a week ago. While
I got it to work, I am not sure what I accomplished since I was not
doing AJAX - I just wanted to replace a non-working client-side
Javascript validation routine.
My journey is detailed in a post: <http://groups.google.com/group/
rubyonrails-talk/browse_thread/thread/0e4cf37dbfab4d94?hl=en#>
I''ve had limited response on rails3 questions since probably less that
10% of those on the list are currently trying it. I did do some
experimenting with what I think you are trying to do. One approach is
to wrap your checkbox in a link:
<%=link_to( check_box_tag( "selection", "1",
false, {:id =>
user.id}) , "/yoururl/1", :remote => true) %> One
In tracing the javascript it will do a GET request to /yoururl/1
if you do:
<%=link_to( check_box_tag( "selection", "1",
false, {:id =>
user.id}), "/yoururl/1", :remote => true, :"data-method"
=>
"showHideMenuItem") %> One
That will try a POST request to /yoururl/1
If you do "
<%=link_to( check_box_tag( "selection", "1",
false, {:id =>
user.id}), "/yoururl/1" :"data-method" =>
"showHideMenuItem") %> One
That will act like the delete action and build a form and submit try
to submit it.
Somewhere in there you have to deal with the checkbox. I''ve never
experimented with a xxx.js.erb file, so I guess you do it there.
Hope this gives you a start.
On Aug 17, 11:52 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
wrote:> I have current a js function call I would like to transform into an
> Ajax request
>
> = check_box_tag "selection", "1", false, {:id
=> user.id, :onclick =>
> "showHideMenuItem(this);"}
>
> I found a lot of examples on link_to , but none on a checkbox .. I
> know I have to add :remote => true somewhere, but that''s all I
> know ..
>
> please, any help or tip will be welcome !
>
> thanks a lot for your links...
>
> erwin
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
shahroon ali
2010-Aug-18 10:13 UTC
Re: Re: how to write an Ajax call w the new unobtrusive js ?
Well, why not try observe_field? like this i did
<%= check_box :campaign, :use_global, {}, 1,0 %>
<%= observe_field :campaign_use_global, :url => {:controller =>
"metakeys",:action => ''update_metakeys_flag'', :id
=> parent_id, :type =>
"campaign"}, :with => "''val=''+value",
:method => :post %>
Thanks
On Wed, Aug 18, 2010 at 2:34 PM, AppleII717
<salex-ee4meeAH724@public.gmane.org> wrote:
> The rails.js UJS file appears to handle only links/anchors or forms.
>
> I went through a "I want to do this with UJS" about a week ago.
While
> I got it to work, I am not sure what I accomplished since I was not
> doing AJAX - I just wanted to replace a non-working client-side
> Javascript validation routine.
>
> My journey is detailed in a post: <http://groups.google.com/group/
>
rubyonrails-talk/browse_thread/thread/0e4cf37dbfab4d94?hl=en#<http://groups.google.com/group/%0Arubyonrails-talk/browse_thread/thread/0e4cf37dbfab4d94?hl=en#>
> >
>
> I''ve had limited response on rails3 questions since probably less
that
> 10% of those on the list are currently trying it. I did do some
> experimenting with what I think you are trying to do. One approach is
> to wrap your checkbox in a link:
>
> <%=link_to( check_box_tag( "selection", "1",
false, {:id =>
> user.id}) , "/yoururl/1", :remote => true) %> One
>
> In tracing the javascript it will do a GET request to /yoururl/1
>
> if you do:
>
> <%=link_to( check_box_tag( "selection", "1",
false, {:id =>
> user.id}), "/yoururl/1", :remote => true,
:"data-method" =>
> "showHideMenuItem") %> One
>
> That will try a POST request to /yoururl/1
>
>
> If you do "
>
> <%=link_to( check_box_tag( "selection", "1",
false, {:id =>
> user.id}), "/yoururl/1" :"data-method" =>
"showHideMenuItem") %> One
>
> That will act like the delete action and build a form and submit try
> to submit it.
>
> Somewhere in there you have to deal with the checkbox. I''ve never
> experimented with a xxx.js.erb file, so I guess you do it there.
>
> Hope this gives you a start.
>
>
> On Aug 17, 11:52 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
wrote:
> > I have current a js function call I would like to transform into an
> > Ajax request
> >
> > = check_box_tag "selection", "1", false,
{:id => user.id,
> :onclick =>
> > "showHideMenuItem(this);"}
> >
> > I found a lot of examples on link_to , but none on a checkbox .. I
> > know I have to add :remote => true somewhere, but that''s
all I
> > know ..
> >
> > please, any help or tip will be welcome !
> >
> > thanks a lot for your links...
> >
> > erwin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
the remote_function is still alive ..... I finally ended using it, and it works but the Rails 3 doc is not yet very clear about all this remote stuff.... On 18 août, 12:13, shahroon ali <shahroon....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, why not try observe_field? like this i did > > <%= check_box :campaign, :use_global, {}, 1,0 %> > <%= observe_field :campaign_use_global, :url => {:controller => > "metakeys",:action => ''update_metakeys_flag'', :id => parent_id, :type => > "campaign"}, :with => "''val=''+value", :method => :post %> > > Thanks > > > > On Wed, Aug 18, 2010 at 2:34 PM, AppleII717 <sa...-ee4meeAH724@public.gmane.org> wrote: > > The rails.js UJS file appears to handle only links/anchors or forms. > > > I went through a "I want to do this with UJS" about a week ago. While > > I got it to work, I am not sure what I accomplished since I was not > > doing AJAX - I just wanted to replace a non-working client-side > > Javascript validation routine. > > > My journey is detailed in a post: <http://groups.google.com/group/ > > rubyonrails-talk/browse_thread/thread/0e4cf37dbfab4d94?hl=en#<http://groups.google.com/group/%0Arubyonrails-talk/browse_thread/thre...> > > > I''ve had limited response on rails3 questions since probably less that > > 10% of those on the list are currently trying it. I did do some > > experimenting with what I think you are trying to do. One approach is > > to wrap your checkbox in a link: > > > <%=link_to( check_box_tag( "selection", "1", false, {:id => > > user.id}) , "/yoururl/1", :remote => true) %> One > > > In tracing the javascript it will do a GET request to /yoururl/1 > > > if you do: > > > <%=link_to( check_box_tag( "selection", "1", false, {:id => > > user.id}), "/yoururl/1", :remote => true, :"data-method" => > > "showHideMenuItem") %> One > > > That will try a POST request to /yoururl/1 > > > If you do " > > > <%=link_to( check_box_tag( "selection", "1", false, {:id => > > user.id}), "/yoururl/1" :"data-method" => "showHideMenuItem") %> One > > > That will act like the delete action and build a form and submit try > > to submit it. > > > Somewhere in there you have to deal with the checkbox. I''ve never > > experimented with a xxx.js.erb file, so I guess you do it there. > > > Hope this gives you a start. > > > On Aug 17, 11:52 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > I have current a js function call I would like to transform into an > > > Ajax request > > > > = check_box_tag "selection", "1", false, {:id => user.id, > > :onclick => > > > "showHideMenuItem(this);"} > > > > I found a lot of examples on link_to , but none on a checkbox .. I > > > know I have to add :remote => true somewhere, but that''s all I > > > know .. > > > > please, any help or tip will be welcome ! > > > > thanks a lot for your links... > > > > erwin > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.