Syndicate

Feed

Learning Ruby on Rails Day 40

Where did time go? Last time I added an entry to my Learning Ruby on Rails journal, it was May 6th. Today is October 30th. There may have been 40 days of learning between then and now. I am back into it — is what matters. Teaching myself Ruby on Rails has become a sort of yoga practice in my life. It feels mostly good and places a nice comfy shield between all the bad noise in my life and my easily-troubled head.

I have set each chapter of a book I have yet to finish reading as 'action' in my Action Method. The book is Simply Rails 2. I am plowing along. The grass is green and cut short and clean. Patrick Lenz is a fantastic writer. Thanks to him, the pasture smells great. Actually, I smelled something funny tonight. I got back into wrapping my head around RJS templates.

They are written in Ruby. Like *.html.erb templates, they are stored in the views folder. They have the extension .js.rjs because once the Rails engine is done with them JavaScript is returned to the browser. Ah, I am not explaining well. Good definition found in Foundation Rails 2: “RJS is Rails’s solution for generating JavaScript code using Ruby. [It] is a server-side solution for generating dynamic responses to AJAX requests without having to resort to writing [...] JavaScript. [...] RJS code [...] resides in specially named RJS templates that can be found in the same directories as our traditional HTML views. However, whereas our standard view template would be named something like index.html.erb, the RJS template for the same action would be named index.js.rjs. So you can see it [follows] the same naming convention with the first word [being] the action it’s associated to, the second [word] representing the type of content that we’re returning (js for JavaScript in this instance), and the final [word] representing the rendering engine that is used to parse the template (RJS for this).”

I usually install the vendor plugin jRails to get rid of Prototype and script.aculo.us when I build any new application. There exists a jRails gem now, but I didn't have much success with it.

jRails, FYI, has moved to github. “ennerchi” and “aaronchi” are the same guy. To install jRails:
ruby script/plugin install git://github.com/aaronchi/jrails.git

Not sure whose fault it is, probably that of jRails, but I'm sending the authenticity_token twice with every Ajax request.

[]

I am using the form_remote_tag helper:

<% form_remote_tag :url => story_votes_path(@story) do %>
  <p><%= submit_tag 'Shove This' %></p>
<% end %>

The following HTML is generated:

<form action="/stories/5-google/votes" method="post" 
onsubmit="jQuery.ajax({ data:jQuery.param(jQuery(this).serializeArray()) +
'&amp;authenticity_token=' + encodeURIComponent('zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok='),
dataType:'script', type:'post', url:'/stories/5-google/votes'}); return false;">
  <div style="margin:0;padding:0">
    <input name="authenticity_token" type="hidden"
 value="zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok=" /></div>
  <p><input name="commit" type="submit" value="Shove This" /></p></form>

The form already contains a hidden input field that stores the authenticity token (this protects against forgery). jQuery serializes the form, hence serializes that token, but then... it adds it again! That's not right.

data: jQuery.param(jQuery(this).serializeArray()) + '&amp;authenticity_token=' +
encodeURIComponent('zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok='), ...

The following code should suffice:

data: jQuery.param(jQuery(this).serializeArray()), ....

Whatever.

Also, RJS requires some getting used to for me. Seems weird to have an Ajax request return JavaScript to execute, rather than JSON, or text data, or XML, or nothing. I usually use callback functions when doing Ajax: when the data is returned, if any, some JavaScript function is run, doing whatever to the page. There's really different shit happening here, although results are the same of course.

text/javascript; charset=utf-8

The JavaScript returned to the browser is a big Try and Catch. If a JavaScript error occurs, an alert box tells you what went wrong.

try {
jQuery("#vote-score").html("Score: 112");
jQuery("#vote-score").effect('highlight',{},2000);
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('jQuery(\"#vote-score\").html(\"Score: 112\");
\njQuery(\"#vote-score\").effect(\'highlight\',{},2000);'); throw e }

Eh, this looks a bit convoluted:

jQuery.param(jQuery(this).serializeArray())

Couldn't we just use this — not sure:

jQuery(this).serialize()

Unobtrusive jQuery

I prefer unobtrusive jQuery just because it's more manageable. I also like to write my own JavaScript — or at least be able to edit it. Ryan Bates shows here how to use jQuery without jRails. No helper functions. No JavaScript generated for you. Ryan Bates uses Ajax requests that return JavaScript as does jRails. But the JavaScript that's returned is stored, this time, in a .js.erb template.

The form on the page is submitted asynchronously thanks to some jQuery added to application.js. (Shown below.) Ryan Bates uses a simple jQuery.post call. And he does uses jQuery(this).serialize! I may try to modify my Shovell app (the book project in Simply Rails 2) to use a .js.erb template. What we're comfortable with may not be the better way, though. If I get used to using RJS templates, I may learn to love them. Not sure.

How to use jQuery with Rails - Screencast by Ryan Bates

Last edited by Caroline Schnapp about 5 years ago.

Comments

hey

which font do you use in your text editor?

good

Aw, this became an incredibly good quality article. In principle I would like to produce this way way too * spending time along with true hard work to generate a very good document... nevertheless exactly what can I have faith that... My spouse and i delay doing things much and don't apparently go accomplished. There are additional alternatives for beginning ache.

Such a very informatics

Such a very informatics post, as I have browsed the majority of your posts. But I found this post is almost certainly where I got the most useful information for my research. It is really very interesting to read this particular post. I just would like to say thanks for your great efforts.
euro study consultants

They are written in Ruby.

They are written in Ruby. Like *.html.erb templates, they are stored in the views folder. They have the extension .js.rjs because once the Rails engine is done with them JavaScript is returned to the browser. Ah, I am not explaining well.I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog!
90210 Seasons 1-5 DVD Box Set|Lost Girl Seasons 1-3 DVD Box Set|Walt Disney's 100 Years Of Magic 164 Discs DVD Box Set

I'm attracted by your topic

I'm attracted by your topic which i'm interested in.Your article is really excellent and it does much help to me.However, whereas our standard view template would be named something like index.html.erb, the RJS template for the same action would be named index.js.rjs.That is very interesting Smile I love reading and I am always searching for informative information like this. This is exactly what I was looking for. Thanks for sharing this great article.
Doctor Who Seasons 1-7 DVD Box Set|Breaking Bad Seasons 1-6 DVD Box Set|Drop Dead Diva Seasons 1-5 DVD Box Set

Liked theme

This kind of Web site to add, for the report will be restored. Actually, I found exactly my partner and I've looked at the place before the unit did not occur.

They are written in Ruby.

They are written in Ruby. Like *.html.erb templates, they are stored in the views folder. They have the extension .js.rjs because http://e-papierossy.com.pl/en/e-papierosy/101-e-papierosy-zerok-z22121.html once the Rails engine is done with them

http://e-papierossy.com.pl/en/e-papierosy/102-e-papierosy-zerok-z231211.html JavaScript is returned to the browser. Ah, I am not explaining well. Good http://e-papierossy.com.pl/en/e-papierosy/109-e-papierosy-zerok-z9152211.html definition found in Foundation Rails 2: “RJS is Rails’s solution for generating JavaScript code using Ruby. [It] is a server-side solution for generating dynamic responses to AJAX requests without having to resort to writing [...] JavaScript. [...] RJS code [...] resides in specially named RJS templates that can be found in the same directories as our traditional HTML views.

great post

online casino spielgeld||casino spiele onlie There are so many comments here that are really interesting and conducive to me thanks for sharing a link especially for sharing this blog.

When you are traveling with

When you are traveling with a baby, so it assists you search for and discover a place to be able to rest. There are a great number of babies are truly becoming ill

good side

prestige casino || online spielothek
Please add good good information that would help others in such best way.This post is exactly what I am concerned.

good side

prestige casino || online spielothek
Please add good good information that would help others in such best way.This post is exactly what I am concerned.

http://www.buyuniquegifts.net/

Many things can cause a problem occurs. Therefore, I always plan and predict the problems that will occur when I do something that does not become a barrier to prolonged. Birthday Gifts are not always about cake and flowers.

Twin fountains http://twinfountainsed-woodlands.com

this is a great blog. Worth keeping in mind. Hedges Park Condo, Topiary EC, Twin Fountains Woodlands

I would expose the theories

I would expose the theories of René Girard. But at the thought of speaking in front of crowds, I’m scared to death. Get rid of federal estate tax

Thanks to him, the pasture

Thanks to him, the pasture smells great. Actually, I smelled something funny tonight. I got back into wrapping my head around RJS templates. http://www.refrigeratornotcooling.net/

I completed the installation

I completed the installation procedure and everything seems to be OK. But after I made connection, using a tightvnc client, I get a blank screen. At that moment there is no user logged in at the host yet. http://idoleyes.com/fashion-blog/

You are absolutely right. If

You are absolutely right. If something gets too slick, it will not feel as real. I totally agree with you. I used to read your posts regularly. http://iqoffice.ca/

great blog

this is an awesome blog worth visiting over and over again. ecopolitan ec executive condominium for sale

Ryan Bates uses Ajax

Ryan Bates uses Ajax requests that return JavaScript as does jRails. But the JavaScript that's returned is stored, this time, in a .js.erb template. Power Boats for sale

It feels mostly good and

It feels mostly good and places a nice comfy shield between all the bad noise in my life and my easily-troubled head. SEO

Great Article

Great article and blog, really i want to tell you.

Great Article

Great article and blog, really i want to tell you.

You are absolutely right. If

You are absolutely right. If something gets too slick, it will not feel as real. I totally agree with you. I used to read your posts regularly. dj remixes

well written

well shared post. thanks for sharing with us this wonderful post. executive condo for sale pasir ris new ec corals at keppel bay

I precisely had to thank you

I precisely had to thank you very much again. I am not sure the things that I would have implemented without the actual techniques contributed by you about this area of interest. http://hacks.seriouslyreview.com/chaturbate-token-hack/

In Drupal 5, there were no

In Drupal 5, there were no less than three ways to achieve this, and I will present these when I'm done covering date formatting for Drupal 6. Drupal 6 allows you to modify the 70-465 different formats for dates in the Administration area of your site, these different formats being small, medium and large — yep, just like pizza, oh... my... god... You could do the same in Drupal 5. http://www.test-insides.com/70-465-exam.html However, you then had to pick among a finite list of options. In Drupal 6, you can create an nth option, if you like none of the options presented to you.

Perfect info

I think that information es great. Please, i want to contact with you. Thanks.

The Inflora Condo is a new

The Inflora Condo is a new and upcoming Flora Road New Launch Condo located in Flora Road, within a short drive to Singapore Expo, Tampines Point, Century Square and IKEA. With expected completion in mid 2017, it comprises of TBA towers with TBA units and stands TBA storeys tall. The Inflora

Bishan Condo is a new and

Bishan Condo is a new and upcoming new launch located in the Bishn area, nested right beside Bishan MRT. Sky Vue is within a short drive to Little India, Orchard and city area. With expected completion in mid 2017, it comprises of 694 units in total with 2 Blocks and 17 storeys. Bishan Condo

LONDON

Thank you so much for this excellent post, as always you manage to both motivate me and excite me - good job and please do keep up the hard work - well all appreciate it very much! GTA 5 Download electronic cigarette reviews

The Hillford Condo has full

The Hillford Condo has full and unique facilities, which includes a guard house, clubhouse, children's playground, swimming pool, Aerobic/Yoga room, piano room, pool room, indoor gym, hydrotherapy beds, hydrotherapy baths, reading room, function room, onsen, jacuzzi. The Hillford

Future residents will be

Future residents will be able to walk from The Hillford Condo to the upcoming Downtown Line Beauty World MRT. Also, nature awaits your family and friends at the nearby Dairy Farm Nature Park and the Bukit Batok Nature Park. Also, the ultimate nature awaits you at Bukit Timah Nature Reserve. The Hillford

Jurong West new Condo Launch by MCL And

Jurong West Condo is a 99-years leasehold Jurong West New Launch Condo development located at Jurong West Street 41. Jurong Condo

So kind of you

It truly is very much exciting to me to write down some of my own trial and error ideals with regards to some of my own online favored best writing service review which can be loved online in particular by means of my own facebook web page. No. connected with readers are generally incorporating day by day. Appreciate it for your form assist.

Several buses are available

Several buses are available near Rivertrees Residences along with shopping centers and restaurants. Rivertrees Residences is also near Waterway Point, the shopping, dining and entertainment hub which is scheduled to open in 2 years time. Also, it is right beside Punggol Waterfront. Entertainment for your loved ones and friends are therefore at your fingertips with the full condo facilities as well as the amenities near Rivertrees Residences. Rivertrees Residences in Fernvale Sengkang

Pet Grooming Centres in Singapore

Getting your dog to eat green vegetables can be quite a challenging task unless you adopt the right approach. Dogs are fond of biscuits or kibbles partly because of the satisfying crunch they experience while eating those items. Eating Vegetables

Sunglade Condo is an

Sunglade Condo is an exciting development near mrt. Sunglade Singapore

Interesting essay! Get more

Interesting essay! Get more informatiom about the best writing service review here.

customizable iphone 5c cases

This post is so interesting and useful for me. Keep up the good work, and post more articles like the one you have posted above. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Good article, this is so well explained that even my kids could follow it, thanks and keep up the great work!

custom iphone 5c cases

Pentru mai multe detalii cu privire la serviciile de gazduire web Pagini Europene vizitati noul lor site si gasiti tot felul de oferte de sezon.

you have a great blog here!

you have a great blog here! would you like to make some invite posts on my blog? online school for girls

Obatt Tradisional Untuk Anak

What is the first word in the phrase "pomupa facav zowa fuwi fihule
obat tradisional untuk anak.
obat tradisional ibu hamil.
obat penurun panas anak.

Which is not something I

Which is not something I usually do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment! nice men watches Choose from thousands of custom clock designs here

Excellent essay

Really excellent essay to get these types of essays in large in number you can approach the best custom essay writing service one of the best on-line writing service available

It's so interesting! thank

It's so interesting! thank you so much.

dfrtyy

Great !! Thank you for this beautiful Artiicle friend

Essay Writing

Very interesting! By the way, you can order excellent papers online! Read the best writing service review!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <css> <html> <javascript> <mysql> <php> <span> <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <javascript>, <mysql>, <php>, <rails>, <ruby>.

More information about formatting options

CAPTCHA
I have to wonder if you're a human spammer or a machine, or less likely someone who cares to leave his or her thoughts behind.