Rails jquery mobile 路由/渲染问题

2024-03-07

我正在关注教程http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/ http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/将直接搭建的 Rails 3 应用程序中的视图转换为 jquery 移动前端。

创建新记录后,我将传递到显示视图,并实际看到显示视图的结果,如显示的记录的两个新创建的字段一样,但是,URL 是http://localhost:3000/货币 http://localhost:3000/currencies在浏览器中。当我查看源代码时,源实际上是索引视图而不是浏览器中呈现的显示视图,这相当奇怪。有什么想法为什么会发生这种情况吗?

Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.10'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'jquery-rails'

Routes:

Mycurrency::Application.routes.draw do
  resources :currencies

  #match ':name' => 'Currencies#show', :as => 'currency_name'

  root :to => 'currencies#index'

控制器:

class CurrenciesController < ApplicationController
  # GET /currencies
  # GET /currencies.xml
  def index
    @currencies = Currency.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @currencies }
    end
  end

  # GET /currencies/1
  # GET /currencies/1.xml
  def show
   # @currency = Currency.find(params[:id])

    if params[:name]
      if Currency.where(:name => params[:name]).first != nil
        @currency = Currency.where(:name => params[:name]).first
      else
        redirect_to root_path
      end    
    else
      @currency = Currency.find(params[:id])
    end

   # respond_to do |format|
    #  format.html # show.html.erb
     # format.xml  { render :xml => @currency }
  #  end
  end

  # GET /currencies/new
  # GET /currencies/new.xml
  def new
    @currency = Currency.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @currency }
    end
  end

  # GET /currencies/1/edit
  def edit
    @currency = Currency.find(params[:id])
  end

  # POST /currencies
  # POST /currencies.xml
  def create
    @currency = Currency.new(params[:currency])

    respond_to do |format|
      if @currency.save
        format.html { redirect_to(@currency, :notice => 'Currency was successfully created.') }
        format.xml  { render :xml => @currency, :status => :created, :location => @currency }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @currency.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /currencies/1
  # PUT /currencies/1.xml
  def update
    @currency = Currency.find(params[:id])

    respond_to do |format|
      if @currency.update_attributes(params[:currency])
        format.html { redirect_to(@currency, :notice => 'Currency was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @currency.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /currencies/1
  # DELETE /currencies/1.xml
  def destroy
    @currency = Currency.find(params[:id])
    @currency.destroy

    respond_to do |format|
      format.html { redirect_to(currencies_url) }
      format.xml  { head :ok }
    end
  end
end

application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title>Mycurrency</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css" />
  <%= javascript_include_tag :defaults %>
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
  <%= csrf_meta_tag %>
</head>
<body>
<div data-role="page">
    <%= yield %>
</div>

</body>
</html>

jQuery Mobile 通过 AJAX 加载页面,将它们添加到 DOM,然后使用所有 jQuery Mobile 样式增强它们。由于这种通过 AJAX 加载页面的方法,当用户在站点中导航时,页面的源不会改变。

要查看当前页面的源代码,您需要刷新网页。

我建议阅读 AJAX 导航的 jQuery Mobile 文档:http://jquerymobile.com/demos/1.0rc2/docs/pages/page-navmodel.html http://jquerymobile.com/demos/1.0rc2/docs/pages/page-navmodel.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails jquery mobile 路由/渲染问题 的相关文章

随机推荐

  • 运行时错误:事件循环正在运行

    当我调用该函数时出现以下错误send message Exception in thread Thread 1 Traceback most recent call last File usr lib python3 4 threading
  • Camel SFTP - 无法将目录更改为“/”

    我需要通过 SFTP 连接到服务器 但收到此错误 INFO org apache camel component file remote SftpOperations connect Connected to sftp myserver c
  • 从 Powershell 中的对象数组中删除项目

    我有一个数组对象 a 它返回如下所示的输出 通过执行 a 0 Name 我可以访问每个 Name 条目 a 0 Available 我可以访问其相应的可用空间 我有另一个数组 b 包含一些名称 例如 b 返回两个名称 sandeep agg
  • 解释 - 不涉及反射

    我有一个非常简单的问题 这不仅适用于 Spray json 而且我读过 argonaut 和 circe 的类似声明 所以请赐教 在 Spray json 中 我遇到这样的声明 There is no reflection involved
  • 如何在没有 ID 的情况下在 Prisma 中更新插入新记录?

    我正在使用 Prisma https www prisma io https www prisma io 作为 ORM 我想在存储数据时检查重复项 如果不存在 则创建一条新记录 我想我可以使用 Prisma 提供的 upsert 方法来做到
  • underscore.js 中的 chain 函数是否创建了一个 monad?

    In the chain文档 http underscorejs org chaining你发现 Calling chain在包装对象上将导致所有未来的方法调用 也返回包装的对象 当你完成后 计算 使用value检索最终值 也是如此chai
  • OpenAPI中如何定义全局参数?

    我正在准备我的 API 文档 方法是手工完成 而不是自动生成 我有应该发送到所有 API 的标头 但不知道是否可以为整个 API 全局定义参数 其中一些标头是静态的 有些必须在调用 API 时设置 但它们在所有 API 中都是相同的 我不想
  • 创建字典时使用语言模型文件

    我创建了一个语音到文本识别应用程序 为此 我使用 CMULanguage 工具开发了一本字典 为了为我的项目创建字典 我在组和文件中的语言文件夹中添加了两个文件 这些文件的扩展名是 lm 语言模型 和 dic 当我上传我的语料库时 CMUL
  • Spring Data JPA JpaRepository.save(entity) 不返回数据库默认值

    我有一个相当简单的问题 在单个事务中 我的代码如下所示 MyClass c new MyClass c setPropA A c myClassRepository save c c setPropC C 我的实体如下所示 Entity T
  • 如何通过 Linq 查询 MongoDB 中的 BsonExtraElements

    我使用 mongodb BsonExtraElements 功能来扩展我的类的一些动态数据 但不幸的是我无法通过 mongodb C 驱动程序创建查询 这是我的模型类 public class MongoProductEntity publ
  • 无法检索 ApplicationUser 的元数据。 - VS13

    当我选择使用实体框架生成带有视图的 MVC5 控制器时 我收到以下错误 无法检索 ApplicationUser 的元数据 不支持每种类型的多个对象集 对象集 ApplicationUsers 和 Users 都可以包含 Applicati
  • 无法处理的 POSIX 信号的返回代码

    This is regarding the application that runs on POSIX Linux environment Most signals e g Ctrl C signal 2 SIGINT and few o
  • 计算圆内的坐标

    我正在按钮中间画一个假想的圆圈 圆的半径是Height 2 if Height gt Width or Width 2 if Width gt Height 现在我必须计算这个圆圈中有哪些坐标 以像素为单位 这个想法是 如果例如鼠标光标悬停
  • 如何在 NSUserDefaults 中保存 NSMutableArrays

    我有 4 个带有单独数据的 NSmutablearrays 现在我需要将它们单独保存在 NSuserdefaults 中并单独检索它们 我怎样才能做到这一点 任何人都可以发布一些代码吗 提前谢谢你 数组的内容是什么 虽然 NSUserDef
  • abs() 与 fabs() 速度差异以及 fabs() 的优势

    我对 abs 和 fabs 函数进行了一些简单的测试 但我不明白使用 fabs 的优点是什么 如果是 1 较慢 2 仅适用于浮子 3 如果用在不同的类型上会抛出异常 In 1 timeit abs 5 10000000 loops best
  • DateTime.MinValue 和 SqlDateTime 溢出

    我不想验证txtBirthDate所以我想通过DateTime MinValue在数据库中 我的代码 if txtBirthDate Text string Empty objinfo BirthDate DateTime MinValue
  • 堆栈粉碎后的错误信息如何处理

    我的 C 程序在 Linux 上遇到一些问题 它在 Windows 上编译并运行得很好 Linux 终端返回以下信息 stack smashing detected student terminated Backtrace lib libc
  • Gradle 7 和 jitpack.io 在发布过程中遇到错误

    当我将 Android 项目升级到 Gradle 7 0 并想要在 jitpack io 中发布 aar 库时 我遇到了 Script script maven plugin gradle line 2 What went wrong A
  • Caliburn.Micro:从 IResult 中的异常中恢复

    这是张贴在Caliburn Micro 讨论 http caliburnmicro codeplex com Thread View aspx ThreadId 244394还 我真的在寻找有关最佳解决方法的建议和意见 假设我有以下操作 p
  • Rails jquery mobile 路由/渲染问题

    我正在关注教程http fuelyourcoding com getting started with jquery mobile rails 3 http fuelyourcoding com getting started with j