Live form validation using with jQuery/Coffee AJAX Rails - ruby-on-rails

Okey, so I have this problem... And I've had it for like weeks. I'm working on a school project and I'm supposed to make a live form validation using Ruby on rails and ajax (jQuery/Coffee). I've google my arse off and I've found loads and loads of plugins for it, but not one helpful tutorial. I've got some code together that seems legit, but I need help to make this code validate the form live, checking the database for email, username etc. It's for the sign up page so I think you get the idea.
$("#new_user").live "ajax:beforeSend", (event, xhr, status) ->
form = $(this)
form.validate {
# Validations goes here, but how do I write it?
}
false unless form.valid()
So I guess I'm suppose to write a controller to handle the validations through this jQuery. I'm really new to both Rails and Ajax, so please help me out here.

Your school project will probably be due by now, but here goes anyway.
Check out https://github.com/bcardarella/client_side_validations.
If you use this, you don't need to worry about writing javascript to validate your form. You just need to worry about writing the correct validations in your model.
This might help get you started http://railscasts.com/episodes/263-client-side-validations.
Also if you are new to rails you should know that for most common problems and for a lot of not so common problems there is a solution in the form of a gem.
So if you need to write sign-in/sign-up functionality you might want to check out https://github.com/plataformatec/devise. Which also has a railscast http://railscasts.com/episodes/209-introducing-devise.
Finally here is wiki page that explains how to make client_side_validationsand simple_form work together https://github.com/bcardarella/client_side_validations/wiki/Using-Devise.
Hope this helps.

Related

hash link and force to reload/refresh page in emberjs && rails

etc,
current page and link: '/lessons/4' which is a normal page without emberjs
and I want to redirect to
'/#/sections/2'
next_page
Because the link is with hash, it will not reload in the next_page.
So how can I force it to reload?
My current solution is
Start
Do you have any better solutions?
A better way to do this is to set an event handler on hash change.
See also this question that might help you. I am not familiar with emberjs.
Also, rails support unobtrusive JavaScript, it is good practice to code following this principle.

I want to make an ajax driven static site in RoR

My goal is to create a Rails based site that uses AJAX to fetch different sections. The site should never completely refresh. I'm using Rails 3.2.8.
There's a lot of conflicting articles online about how to actually implement this. It seems to me that simply fetching pages.json and using javascript would accomplish my goal, but is that the "rails" way?
Every page that is users will see is static. I'll be using Rails as an admin to CRUD them, but that's it, and that portion doesn't need to be AJAX.
Take a look at backbone.js. For an ajax heavy site, that's exactly what you need to help organize your code and keep your front end consistent with your database. Also, check out this excellent railscast on implementing backbone in a rails project.
I noticed that you said static site. Well, if the site is completely static, why bother with something like rails? I would suggest just coding it in html and javascript because rails is intended to be used for dynamic, database driven sites.

Subscribe to newsletter form rails 3

I'm new to rails and I would like to know how to make a form that submits to a database. I have tried devise but it seems that it deals with logins/users and it's not working for my purpose. I don't want anyone to do it for me, I have to learn :).
Creating a form that saves to a database is probably on of the most basic tasks to do with rails and is even handled in the "Getting Started"-Chapter in the Rails-Guides:
http://guides.rubyonrails.org/getting_started.html
Just work on that and you'll get the idea. It looks like it's a lot to do on that page, but it explains also the principles and all that. It becomes really interesting for you in chapter 5 and 6.
Creating a form With Rails 3 is exactly like in Rails 2.

Ruby on Rails, AJAX examles

I'd like to know what people think what websites are good examples of AJAX with Ruby on Rails at the moment.
I'm learning both and would like to see some good interesting examples of what can be done.
THanks,
Joe
http://haystack.com/
http://rubyonrails.org/applications
These links will open a new horizon for you.
Perhaps grab a copy of http://www.redmine.org/ and look it over. Maybe not the bleeding edge of ajax but there is some good stuff in there all around for rails development. I learned a lot from it.
If you're just getting started and interested in unobtrusive AJAX with jQuery, I have a blog post you might be interested in. Basically it takes a simple scaffold generated site and adds unobtrusive deleting with jQuery step by step - if that sounds like something you'd be interested in feel free to check it out.
Twitter.com is an excellent example of what can be done with AJAX. I believe the site is coded in Ruby on Rails as well.

AJAX Rails Validation

I have my form and validation working great with regular http requests. I would like it to use AJAX. I know i can validate on the client side but that seems redundant given that I have defined the validations in my model.
As the user is filling out the form, I'd like to give feedback to them on their entries. What is the best way to use the rails defined validations in an AJAX form and give live feedback?
Check out the live-validations plugin. There's also an introductory screencast.
For Rails 3 check out Client Side Validations: https://github.com/bcardarella/client_side_validations
Here's the railscast: http://railscasts.com/episodes/263-client-side-validations
Live-validations was kinda messy to get working for me, so I started with my own solution from scratch backed by Validatious. It's actually really DRY because of the Rails conventions in the back that made it possible to do a lot of smart assumptions. In most cases, all you need is to include a few javascript dependencies and declare your validations in your models as always - and it all just works! =) Peep the README for details.
Here it is:
http://github.com/grimen/validatious-on-rails
If you're looking for a solution to this that does not introduce any plugin dependencies check out my screencast on the issue:
AJAX Validations on Rails 2.3.8
https://github.com/augustl/live-validations/wiki has installation instructions.
When you add LiveValidations.use :jquery_validations to the bottom of your environment.rb, make sure it is outside of the Rails::Initializer block.

Resources