如何在 Rails 中创建单页应用程序? [英] How do I create a single page application in Rails?

查看:43
本文介绍了如何在 Rails 中创建单页应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在完成出色的Rails 教程后,我正在创建我的第一个 Rails 3.2 应用程序.

I'm creating my first Rails 3.2 application after completing the excellent Rails Tutorial.

我希望我的应用程序执行此操作:

I would like my application to do this:

从数据库中提取一个随机配方(我已经使用索引"操作和这段代码完成了这一点:@recipe = Recipe.find(:first, :order => 'Random()'))

Pull a random recipe from the database (I have finished this bit using the 'index' action and this bit of code: @recipe = Recipe.find(:first, :order => 'Random()'))

如果用户点击类似的东西"按钮,应用会从数据库中获取相关配方

If the user clicks the 'something similar' button, the app fetches a related recipe from the db

如果用户点击不同的东西",应用会获取一个不相关的食谱

If the user clicks 'something different', the app fetches an unrelated recipe

据我所知,类似的东西"和不同的东西"都应该有一个动作.这是正确的吗?

From what I understand, there should be an action for both 'something similar' and 'something different'. Is this correct?

我是否应该使用带有不同的东西"和类似的东西"的提交按钮的 POST 表单来确定要采取的操作?

Should I use a POST form with submit buttons for 'something different' and 'something similar' to determine which action to take?

另外,我怎样才能让用户始终停留在一个页面上(所以他们总是将 URL 视为 http://www.whatshouldicookfordinner.co.uk 而不是/recipes#somethingdifferent)?

Also, how can I keep the user on a single page throughout (so they always see the URL as http://www.whatshouldicookfordinner.co.uk rather than /recipes#somethingdifferent)?

推荐答案

使用 javascript 框架/库(Ember、Backbone、Angular、Knockout、Meteor、Batman 等)

Use a javascript framework/library (Ember, Backbone, Angular, Knockout, Meteor, Batman, etc..)

看看这个 railscast:http://railscasts.com/episodes/323-backbone-on-rails-part-1

Check out this railscast: http://railscasts.com/episodes/323-backbone-on-rails-part-1

这篇关于如何在 Rails 中创建单页应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆