PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > AJAX without Rails
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
AJAX without Rails

Réponse
 
LinkBack Outils de la discussion
Vieux 20/11/2007, 16h34   #1
Miki Vz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut AJAX without Rails

Hi, I'm pretty new to Ajax.

I need to do some simple web interfaces for some project I have. A
friend told me Rails was a bit to much for what I need, so I'm using
eruby and markaby, and I'm pretty happy, and things are kept pretty
sweet and simple for now.

However I would like to use a little of Ajax, what is the best way to go
about it? How do Ajax work for ruby? seems like rails has support for
Ajax that makes it simple. Can i have the same for my eruby scripts
without having to install any MVC system like Rails or anything?

I would basically would like to use Ajax to send parts of the page to be
process on the server and use the results to modify how this parts are
shown. For example, send a paragraph from the page to perform named
entity extraction, and then use the results to highlight these named
entities.

Thanks for your time.

- mikisvaz
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 20/11/2007, 17h04   #2
Miki Vz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

Actually, I'm not sure I'm using eruby, I'm using mod_ruby and
generating the html with markaby. I'm a bit lost with all the technology
:p.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 20/11/2007, 17h40   #3
Miki Vz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

Isn't this precisely a rails tutorial? I'm trying not to use rails,
since I really have no database or anything.


Deepak Vohra wrote:
> http://www.regdeveloper.co.uk/2007/0...ails_tutorial/
>
> Miki Vz <mikisvaz@yahoo.com> wrote: Actually, I'm not sure I'm using
> eruby, I'm using mod_ruby and
> generating the html with markaby. I'm a bit lost with all the technology
> :p.


--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 20/11/2007, 18h12   #4
Miki Vz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

:'(. Ok then, thanx.

Deepak Vohra wrote:
> Ruby on Rails is the only Ajax framework for Ruby.
> http://ajaxpatterns.org/Ruby_Ajax_Frameworks
>
> Miki Vz <mikisvaz@yahoo.com> wrote:
> Isn't this precisely a rails tutorial? I'm trying not to use rails,
> since I really have no database or anything.


--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 21/11/2007, 11h54   #5
Eivind Eklund
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

On Nov 20, 2007 5:34 PM, Miki Vz <mikisvaz@yahoo.com> wrote:
> Hi, I'm pretty new to Ajax.
>
> I need to do some simple web interfaces for some project I have. A
> friend told me Rails was a bit to much for what I need, so I'm using
> eruby and markaby, and I'm pretty happy, and things are kept pretty
> sweet and simple for now.
>
> However I would like to use a little of Ajax, what is the best way to go
> about it? How do Ajax work for ruby? seems like rails has support for
> Ajax that makes it simple. Can i have the same for my eruby scripts
> without having to install any MVC system like Rails or anything?


AJAX is fairly simple, at least as long as you ignore the "XML" part
of it and use HTML or JSON (Javascript Over Network) to deal with it.

The very easiest way to do AJAX is to just have a new command
handler/new script that output the HTML you want to replace with, and
do something like this (example with the jQuery library):

<!-- Include jQuery library, replace with your own copy -->
<script type=3D"text/javascript"
src=3D"/publish/files/jquery-nightly-20070801.js"></script>

<!-- Add a method to jQuery for pure replace; this can also be done
other ways, I just included this because this is how my code was
structured already -->
<script type=3D"text/javascript">
jQuery.fn.replace =3D function() {
var stack =3D [];
return this.domManip(arguments, true, 1, function(a){
this.parentNode.replaceChild( a, this );
stack.push(a);
}).pushStack( stack );
};
</script>

<!-- Actual AJAX (actually, AJAH - Asynchronous Javascript And HTML) -->
<!-- Notice: the ready setup here is to call this stuff when the page
DOM is ready.
What happens here is that the POST equivalent of
approve.wa2?_cmd=3Dclose_edition;EditionId=3D2747 gets called,
outputs some HTML, and the #editioncloser input element shown
below gets replaced with
whatever that HTML describes. You can trivially replace what
script gets called, what args it takes, and which element it replace.
-->
<script type=3D"text/javascript">
<!--
$(document).ready(function(){
$("#editioncloser").click(function(){
$.post("approve.wa2", { EditionId: 2474, _cmd: "close_edition" },
function(data) {
=09$("#editioncloser").replace(data);
});
return false;
});
});
-->

</script>

<!-- HTML code for the input element that I will be replacing -->
<input type=3D"submit" value=3D" Lukk utgave " id=3D"editioncloser">


That's simple AJAX.

If you want to include JSON data and do DOM manipulation directly, you
can do JSON calls like this:

$.getJSON("/autodb/ajaxapi.wa2",{_cmd: cmd, xBoatType: xBoatType,
xBrand: xBrand, xModel: xModel}, function(j) {
var elm =3D document.forms['search'].elements[id];
RemoveChildren(elm);
for (var i=3D0; i<j.length; i++) {
AddOption(j[i].optValue, j[i].optDisplay, j[i].optSelected, elm=
);
}
})

Here, you need to have your callback method output "JSON", JavaScript
structures outputted over net. You can find examples of it on the
net; for a simple example, here's something that the above script
("ajaxapi.wa2") outputs for one of our structures:
[{optSelected: 0, optValue: 0, optDisplay: 'Alle (80)'},{optSelected:
0, optValue: 8001005, optDisplay: 'Fiskeb=E5t/Sjark (2)'},{optSelected:
0, optValue: 8001008, optDisplay: 'Gummib=E5t (0)'},{optSelected: 0,
optValue: 8001006, optDisplay: 'Jolle/=C5pen b=E5t (4)'},{optSelected: 0,
optValue: 8001010, optDisplay: 'Kano/Kajakk (0)'},{optSelected: 0,
optValue: 8001001, optDisplay: 'Motorb=E5t (64)'},{optSelected: 0,
optValue: 8001003, optDisplay: 'Motorseiler (0)'},{optSelected: 0,
optValue: 8001009, optDisplay: 'RIB (0)'},{optSelected: 0, optValue:
8001012, optDisplay: 'Seilbrett, (0)'},{optSelected: 0, optValue:
8001002, optDisplay: 'Seilb=E5t (8)'},{optSelected: 0, optValue:
8001007, optDisplay: 'Skj=E6rg=E5rdsjeep (0)'},{optSelected: 0, optValue:
8001004, optDisplay: 'Snekke (2)'},{optSelected: 0, optValue: 8001011,
optDisplay: 'Vannscooter (0)'}]

Notice how close it is to Ruby array/hash structure? The only thing
is that hash keys must be followed by : instead of =3D>. Remember to
escape your single-quotes; they almost certainly WILL show up even if
you're sure they won't. (Or at least they did for us...)

Hope that ed a bit.

Eivind.

  Réponse avec citation
Vieux 21/11/2007, 16h54   #6
Michael Neumann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

Miki Vz schrieb:
> :'(. Ok then, thanx.


Keep smiling

AJAX can be so simple with just Mongrel (no Rails required at all!!!!!):

require 'rubygems'
require 'mongrel'
require 'json'

class AjaxHandler < Mongrel::HttpHandler
def process(req, res)
res.start(200) do |header, out|
out << JSON.dump({"Hello" => "AJAX!"})
end
end
end

Mongrel::Configurator.new :host => '127.0.0.1' do
listener :port => 5000 do
uri '/', :handler => AjaxHandler.new
run
join
end
end


All you need are the 'json' and 'mongrel' gems. In your HTML page simply use
jquery (www.jquery.com), and make a AJAX call to the server. That's so easy!

Regards,

Michael


  Réponse avec citation
Vieux 21/11/2007, 20h55   #7
Miki Vz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

Thanks a lot for your replies guys, I have a lot of information here to
digest but I think I know what to look for.

Miki
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 22/11/2007, 14h31   #8
Nicolas Antoniades
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: AJAX without Rails

Hall=E5 Eivind.
E du svensk m=E5nne?
Har sv=E5rt o f=E5 tag p=E5 n=E5gon som faktskt kan f=F6rklara saker o ting=
...
/Nico

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h12.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,20790 seconds with 16 queries