When user turn off JavaScript then follow HTML request flow otherwise follow JS request flow.

当用户关闭JavaScript时,请遵循HTML请求流,否则请遵循JS请求流程。

  • HTML flow means : request as html => render html template => response as HTML ( when JavaScript off in browser )

    HTML流意味着:请求为html => render html template =>响应为HTML(当浏览器中的JavaScript关闭时)

  • JS flow means : request as JS => render JS template => response as JS ( when JavaScript on in browser )

    JS流意味着:请求JS =>渲染JS模板=>响应为JS(当浏览器中的JavaScript时)

I have one solution for that and that is :-

我有一个解决方案,那就是: -

  • I have to write code to handle both request in my all controller something like this :

    我必须编写代码来处理我的所有控制器中的这两个请求:

    respond_to do |format|
     format.html
     format.js
    end
    
  • I have to create both type of template js and html and render common data in it.

    我必须创建两种类型的模板js和html并在其中呈现公共数据。

But in above solution, i think there is very much duplicate code like we have to write respond_to code in every controller and we have to create two copy of every page (js.html, erb.html).

但是在上面的解决方案中,我认为有很多重复的代码,比如我们必须在每个控制器中编写respond_to代码,我们必须创建每个页面的两个副本(js.html,erb.html)。

So i need standard solution(if any) to handle both kind of request based on JavaScript enabled/disable in browser without any duplication.

所以我需要标准的解决方案(如果有的话)来处理基于JavaScript启用/禁用的两种请求,而不需要任何重复。

1 个解决方案

#1


0

You only need to create this block for methods that need to respond to js calls - normally these are ajax methods, and not every method in your application.

您只需要为需要响应js调用的方法创建此块 - 通常这些是ajax方法,而不是应用程序中的每个方法。

Are you really doing everything in your application by ajax? Or just a select few methods?

您是否真的通过ajax在您的应用程序中执行所有操作?或者只是选择几种方法?

更多相关文章

  1. 使用jquery在textarea中的颜色代码
  2. 为什么我的javascript/jquery代码不能像预期的那样工作?
  3. 实现浮动广告的代码
  4. 豆瓣Javascript代码风格规范
  5. 【问题解决方案】ImportError: No module named 'pygal'
  6. Python 黏包及黏包解决方案
  7. 计算机视觉相关代码片段(Python)
  8. 120行python代码解锁10000分微信跳一跳
  9. XGBoost中参数调优的完整指南(含Python-3.X代码)

随机推荐

  1. android 日常 (十六)
  2. Android快速开发架构PlanA(四),网络请求篇,划
  3. android之AnimationDrawable
  4. Android多分辨率适配框架使用指南
  5. Android系统源码基础知识讲解
  6. Dagger 2 在 Android 上的使用(五)
  7. Dagger 2 在 Android 上的使用(四)
  8. [应用代码] android源码之多线程断点续传
  9. Android开发如何设置文字阴影
  10. 恶意吸费之后,你渴望开放还是开源?