铁轨 +脸盒 + authlogic-如何?

发布于 2024-08-28 08:30:32 字数 339 浏览 3 评论 0原文

在我的网站上,我想使用 Facebox(jQuery 插件)在模态窗口中完成登录/注册表单。更好的是:

  1. 使用一种方法和具有表单的模板创建视图,并将 Facebox 引用到该视图。
  2. 在公共目录中创建静态 HTML 文件,并将 Facebox 引用到此静态页面。

我想要实现的是:

  • 轻松验证(例如“用户名已被占用”,“密码确认与密码不匹配”之类的东西)。
  • 轻松提交和重定向

我是 Rails 新手,我只知道 Django 中的表单验证,因此对于 Django 我可能会选择选项 1,但在 Ruby 中可能是另一回事。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-09-04 08:30:32

如果您希望验证返回到注册页面,则应将其设为动态页面。

公共目录中的静态页面的另一个问题是您的链接全部被硬编码,因此如果您的应用程序曾经脱离域根(即 example.com/app),则该静态文件中的链接可能是错误的。

此外,如果您需要将图像移动到不同的主机,您就会失去 image_tag 的优势。

仅当您知道事情不会改变并且需要速度时才使用静态资源。如果你的动态页面太慢,你可以缓存它们,否则你可能会做错什么。

更新:(针对第一条评论)

当您位于公共文件夹中时,无法使用 Rails 函数来构建 URL。如果您需要在 JavaScript 中使用 Rails 生成的 URL,请从 Rails 视图页面触发它们。
一般来说,我会执行以下操作:

在 application.html.erb 的 head 标记中:

<%= yield :headScripting %>

然后在触发 javascript 的视图页面中:

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

这将从模型控制器操作 summary 加载摘要文本。这可能会渲染:text => “summary” 或 render :layout => false 根据您的需要

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文