views:

232

answers:

1

Hello,

on my web site I want to have login/registration form in modal window done using facebox (jQuery plugin). What is better:

  1. Create view with one method and template that has form and refer facebox to this view.
  2. Create static HTML file in public directory and refer facebox to this static page.

What I want to achieve is:

  • Easy verification (like "user name already taken", "password confirmation doesn't match password" and stuff like that).
  • Easy submit and redirect

I'm new to Rails, I just know about forms verification in Django, so for Django I would probably choose option 1, but it might be another thing in Ruby.

+1  A: 

If you want the verification to come back to the registration page, you should make it a dynamic page.

The other problem with a static page in the public directory is that your links all become hardcoded, so if you application ever lives off the domain root (i.e. example.com/app) the links in that static file could be wrong.

Additionally, if you ever need to move your images to a different host, you lose the advantages of the image_tag.

Only use static resources if you know things won't change and you need speed. If your dynamic pages are too slow, you can cache them, or you might be doing something wrong.

UPDATE: (to address the first comment)

You can't use the rails functions to build your URLs when you are in the public folder. If you need rails generated URLs in your javascript, trigger them from a rails view page. Generally, I'll do the following:

In application.html.erb in the head tag:

<%= yield :headScripting %>

Then in the view page that is triggering the javascript:

<% content_for :headScripting do %>
    jQuery().ready(function() {
        jQuery("#placeholder").load("<%= summary_model_path(@model) %>");
    });
<% end %>

That would load the summary text from the model controller action summary. This would probably render :text => "summary" or render :layout => false depending on your needs

danivovich
How can I refer to a dynamic page from javascript? I'm planning to use jQuery for this, so I will append my event handler in application.js.
Vitaly