Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
remote links with lowpro and rails
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
patrick  
View profile   Translate to Translated (View Original)
 More options 21 May, 20:09
From: patrick <patrick99...@gmail.com>
Date: Thu, 21 May 2009 12:09:29 -0700 (PDT)
Local: Thurs 21 May 2009 20:09
Subject: remote links with lowpro and rails
Hi everyone,

I was just reading this article:  http://blog.7actionsdev.com/2008/06/unobtrusive-rails-links-and-forms...

which advised me to use a regular link with the class "remote", and if
javascript is disable it will function like a regular link, and if
it's enabled it will function as an ajax call.

the article said I need to add to my page's js:

  Event.addBehavior({
   'a.remote'   : Remote.Link,
   'form.remote': Remote.Form});

...  I did this and firebug gives me:

Remote is not defined
'a.remote' : Remote.Link,

..  not sure why it says that, and how to correct it..  Any ideas?

Thank you!
-patrick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bryan Ray  
View profile   Translate to Translated (View Original)
 More options 21 May, 20:21
From: Bryan Ray <br...@bryanray.net>
Date: Thu, 21 May 2009 14:21:44 -0500
Local: Thurs 21 May 2009 20:21
Subject: Re: remote links with lowpro and rails

are you sure that you're including the lowpro library?

--
Bryan Ray
http://www.bryanray.net

"Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning."


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
patrick  
View profile   Translate to Translated (View Original)
 More options 21 May, 20:25
From: patrick <patrick99...@gmail.com>
Date: Thu, 21 May 2009 12:25:26 -0700 (PDT)
Local: Thurs 21 May 2009 20:25
Subject: Re: remote links with lowpro and rails
On 21 May, 12:21, Bryan Ray <br...@bryanray.net> wrote:

> are you sure that you're including the lowpro library?

yes, my source shows:
  <script src="/javascripts/lowpro.js?1157585946" type="text/
javascript"></script>

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Solomon White  
View profile   Translate to Translated (View Original)
 More options 21 May, 20:48
From: Solomon White <rubys...@gmail.com>
Date: Thu, 21 May 2009 13:48:55 -0600
Local: Thurs 21 May 2009 20:48
Subject: Re: remote links with lowpro and rails

If you're using the lowpro linked from the blog post, you should be set, it
defines Remote.  If you downloaded from somewhere else, check inside your
lowpro.js and make sure that it has something like "Remote =
Behavior.create...".  If it doesn't, there should have been a remote.js with
your download that you'll need to include as well.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
patrick  
View profile   Translate to Translated (View Original)
 More options 21 May, 22:43
From: patrick <patrick99...@gmail.com>
Date: Thu, 21 May 2009 14:43:40 -0700 (PDT)
Local: Thurs 21 May 2009 22:43
Subject: Re: remote links with lowpro and rails

> If you're using the lowpro linked from the blog post, you should be set, it
> defines Remote.  If you downloaded from somewhere else, check inside your
> lowpro.js and make sure that it has something like "Remote =
> Behavior.create...".  If it doesn't, there should have been a remote.js with
> your download that you'll need to include as well.

Aha..  Yes, that indeed was the problem.  Thank you!

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
patrick  
View profile   Translate to Translated (View Original)
 More options 22 May, 08:46
From: patrick <patrick99...@gmail.com>
Date: Fri, 22 May 2009 00:46:09 -0700 (PDT)
Local: Fri 22 May 2009 08:46
Subject: Re: remote links with lowpro and rails
I have another problem with this--  It seems that when I try to do a
link to a destroy action, by having :method => :delete in the link_to,
it initiates both an ajax call AND a http request simultaneously when
clicking the link...  Very strange...  I even tried making a separate
route map.resources :comments, :member => {:remove => :delete} .. but
that did not work either.

The only way I was able to figure out how to get around this, was to
rename my destroy action to 'show', and then get rid of the :method
=> :delete in the link_to.

If anyone has any ideas as to why this is, and how perhaps a better
way of how to correct it would be, I'd greatly appreciate it...

my code was:
 <%= (link_to "remove that does not work", comment, :method
=> :delete, :class => 'remote' ) %>

 <%= (link_to "remove that works", comment, :class => 'remote' ) %>

and then my controller action was just:
  def show # works
    @comment = Comment.find(params[:id])
    @comment.destroy
     respond_to do |format|
         format.html { redirect_to :back }
         format.js { render :template => 'comments/destroy.js.rjs' }
      end
  end

  def destroy # does not work
    @comment = Comment.find(params[:id])
    @comment.destroy
     respond_to do |format|
         format.html { redirect_to :back }
         format.js { render :template => 'comments/destroy.js.rjs' }
      end
  end


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jarkko Laine  
View profile   Translate to Translated (View Original)
 More options 22 May, 10:08
From: Jarkko Laine <jar...@jlaine.net>
Date: Fri, 22 May 2009 12:08:29 +0300
Local: Fri 22 May 2009 10:08
Subject: Re: remote links with lowpro and rails
Hi Patrick,

On 22.5.2009, at 10.46, patrick wrote:

> I have another problem with this--  It seems that when I try to do a
> link to a destroy action, by having :method => :delete in the link_to,
> it initiates both an ajax call AND a http request simultaneously when
> clicking the link...  Very strange...  I even tried making a separate
> route map.resources :comments, :member => {:remove => :delete} .. but
> that did not work either.

The problem is with the javascript, not within the Rails code. When  
you add a :method => :delete option to a link_to call, Rails makes the  
link to use javascript to send a form with http (pseudo-)method  
DELETE.  This is because normal links always use the GET method, which  
can never reach the destroy action in Rails. Check out the html source  
of the page in your browser to see what a link_to call produces when  
you use the DELETE method.

Now your problem is that two javascript event handlers are competing  
for your link and it seems in your case they are both firing. However,  
the Low Pro version has no way to know about the DELETE method you  
need for your Remote.Link call to go to the destroy action. Thus it  
will just load the /comments/x page normally, resulting in a request  
to the show action.

The first thing you should do is to remove the :method => :delete  
option from the link_to call. It will just add inline javascript to  
your html which is basically impossible to make accessible, because  
*normal links can not reach you destroy actions* (and neither should  
they).

It's worth repeating here: normal links can only fire GET requests and  
they should never cause any changes in the application state.

Instead, replace the delete link with a simple form (with :method  
=> :delete) and attach Remote.Form to it the same way you're doing  
with links. You can then either use normal submit form button (<input  
type="submit">) in there, or an image input element (<input  
type="image"...>) or if you really want to go hard-core, a button  
element [1]. Then you can just wrap this all up in a reusable helper  
method.

[1] http://particletree.com/features/rediscovering-the-button-element/

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://odesign.fi

Check out my latest book, Unobtrusive Prototype, fresh off the  
Peepcode oven:
http://peepcode.com/products/unobtrusive-prototype-js


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
patrick  
View profile   Translate to Translated (View Original)
 More options 13 July, 05:14
From: patrick <patrick99...@gmail.com>
Date: Sun, 12 Jul 2009 21:14:58 -0700 (PDT)
Local: Mon 13 July 2009 05:14
Subject: Re: remote links with lowpro and rails
Hi there,

I have another question...  I currently have a button that toggles the
visibility of my shopping cart:

button_to_function "view cart", "toggleCart();"

....

I am just curious, if I want to modify this so that when users without
javascript click on this, it would refresh the page with cart=true/
false in the params-- but users with javascript it will simply call
the js function...  Would the most logical thing to do be to just do
something like

link_to "view cart", some_url(:cart => params[:cart] ? false :
true), :onclick => 'toggleCart();', :id => 'toggle_cart'

...  and then in my onload js just do:

$('toggle_cart').src = "#toggle_cart";

....

Or is there a better way?

-patrick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sergio Cambra .:: entreCables S.L. ::.  
View profile   Translate to Translated (View Original)
 More options 13 July, 10:41
From: "Sergio Cambra .:: entreCables S.L. ::." <ser...@entrecables.com>
Date: Mon, 13 Jul 2009 11:41:46 +0200
Local: Mon 13 July 2009 10:41
Subject: Re: remote links with lowpro and rails
On Lunes, 13 de Julio de 2009 06:15:42 patrick escribió:

The best way would be:

link_to "view cart", some_url(:cart => params[:cart] ? false : true), :id =>
'toggle_cart'

and add a behaviour:

Event.addBehavior({
  '#toggle_cart:click': function(event) { toggleCart(); return false; }

--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) ser...@entrecables.com

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google