Data for AJAX req in Rails on the fly – solution

There is solution with Rails helper to issue from my last post. Simple use :with to pass JavaScript variable name.

remote_function (:update => 'results', 
:url => {:action => search_points}, :with => 'dataForSearch')

gives exactly what is needed:

new Ajax.Updater('results', '/route/search_points',
{asynchronous:true, evalScripts:true, parameters:dataForSearch});

Generating data for AJAX req in Rails on the fly

It is possible – read in next post.

Well… I’m starting with AJAX, and my first impressions are very positive. I was skeptical to JS but more I try more I like it. Maybe I don’t like troubles with debugging (like – does know anyone if Venkmann can set breakpoint in JS code embedded in HTML, not in standalone files?).

Go back to details. In Rails there are helpers like link_to_remote, remote_functions, etc to make AJAX fun and easy. But just at start I run across issue. I’m experimenting with some Google Maps mashup and I wanted to call XHR request with data generated in JS on my page. And looks like I can not find way to mix Rails helper with JavaScript generated data. Let’s take example: I want to pass bounds of current map via XHR to find all points covered by current map. I prepared via call to map.getBounds data in string called dataForSearch. So ideally I could use helper remote_function (:update => 'results', :url => {:action => search_points}, :parameters => 'dataForSearch'). Unfortunately, there is no :parameters option.

Continue reading

JOE and Rails or how to color RHTML

I’m using JOE as my text editor. I’m used to it and it is hard to change own habits. When I have got interested in Rails, I tried some other editors with support for Rails/Ruby (for UNIX text terminals). I was very close to use VIM with plugins for Rails. But to much habits from JOE. After few days I was tired, so I returned to JOE.

JOE has nice coloring syntax support and current version (3.5) have support for Ruby. But not for RHTML. RHTML templates looks very ugly in JOE when using HTML coloring scheme. So I sat read c.jsf which has some comments and changed html.jsf to fix most annoying issues. Still I’m not expert :)) with JOE’s coloring, but at least all <% are not so highlighted. I will try to get more from this, maybe even Ruby syntax coloring inside <% %>

Go and fetch this beta from