- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在尝试将数据从 html.erb 文件(在我的 ruby on rails 网站中)发布到 php 脚本,我想知道这是否可能。到目前为止,当我从我的 html.erb 文件中尝试这段代码时,我得到了“缺少模板”
<form method="POST" action="uam_handle_form">
<input type="text" name="email" placeholder="Enter email address" id="email" class="email-input">
<input type="hidden" name="password">
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<div class="connect">
<button type="submit">CONNECT</button>
<label class="control control--checkbox">Opt in all marketing communications from X
<input type="checkbox" checked="checked"/>
<div class="control__indicator"></div>
</label>
</div>
</form>
其中“umm_handle_form”是一个 php 文件。我相信我在 rails 上正确设置了路由,因为如果我将文件扩展名更改为 html.erb,页面将呈现纯文本 php。
有什么方法可以从这个表单提交中发布、接收和运行 php 文件?谢谢!
最佳答案
这个问题类似于Run a php script in ruby on rails ,尽管该问题询问如何在您从 View 运行时从 Controller 运行 php。不过,另一个问题有一个公认的答案,即通过系统命令(反引号)从 Ruby 服务器运行 PHP 脚本。
因此,您应该采取的步骤如下:
通过 AJAX 将表单提交到运行 php 脚本的 Rails Controller 端点,如下所示:
@script_result_string = `php script`
render json: { result: @script_result_string }.to_json
然后在您的 AJAX 回调中,读取 response.result
以获取字符串形式的结果。
如果您尝试使用 PHP 运行浏览器代码,这可能不是一个可接受的解决方案。我认为这样做并不容易。换句话说,您必须将 PHP 代码限制为仅用于服务器的内容。
关于php - 从 html.erb 表单运行 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38469755/
我在 Rails 应用程序上使用 chessboard-0.3.0.js。由于 Rails Assets 管道的问题,我必须编辑渲染图像的 js 代码的每个部分,例如 Pieces。chessboar
我有一个简单的 fixture.yml 文件: label: body: "" 问题是 ERB 代码被解析为加载 fixture 的一部分,而我实际上希望正文字面意思是“”(未插值)。 如何逃
这是erb3.rb require 'erb' weekday = Time.now.strftime('%A') simple_template = "Today is ." renderer =
name.html.erb 和 name.erb 有什么区别?特别是,是否有任何原因导致 name.erb 不好用? 我知道 name.html.erb 是约定 - 这表示 HTML 模板和 ERB
.erb、.rhtml 和 .html.erb 之间有什么区别? 最佳答案 没什么,真的。这只是 Rails 1 和 Rails 2 之间理念的改变。在 Rails 2 之前,有 file.rhtml
我想知道是否有一个 API 可以很好地支持 eRuby (erb) 和 JavaScript 突出显示、语法分析和代码辅助。 我已经尝试过使用 Aptana 来使用 Eclipse RadRails
我正在尝试在 Rails 应用程序上的示例 ruby 上实现 jquery。我刚刚开始探索js。我知道我在 js/jquery 方面还有很多东西要学。现在有件事让我很困惑。 我有一个 js.erb
我有一个导航栏,它显示未读消息数。未读计数必须在导航栏文本中进行格式化,因此我使用了以下内容: false}).count(:id, :distinct => true).to_s}", conve
我正在编写一个显示代码和输出的样式指南。它目前的结构使得代码只需要描述一次,并以其原始版本和解释版本显示,如下所示: #{ image_tag 'image.png' } PLACE_THE
我的大多数 js.erb 文件底部都包含类似这样的内容: $("#flash_message").html(" "note")) %>"); $("#flash_message").fadeOut(2
我的目标是使用相同的 Controller 调用 html.erb 和 js.erb 文件,但它只调用我的 html 文件。 我的 js 没有被调用。 Controller /categories_c
尝试将* .html.slim View 转换为* .html.erb。 我看了以下两个问题: How can I convert html.slim to html.erb?-从控制台调用时获取un
我正在 Eclipse 中开发 jRuby on Rails 应用程序。我最近安装了 Aptana 以更好地支持 rails 文件。这为大多数文件类型提供了合理的突出显示和支持,包括“html.erb
过去几天我一直在尝试理解 Rails 上 AJAX 的不同方面。在阅读了一些介绍后,我对 Rails 内置的 UJS 功能有了一定的了解。我编写的一个小玩具应用程序的示例,我想在其中引入一些 AJAX
我在不同模型的 ajax 响应之间有重复的 js.erb 代码。我想通过将参数传递到 js.erb 部分来重构重复的 js.erb 代码。 如何从 js.erb 文件渲染 js.erb 部分? 最佳答
我的 Rails 应用程序正在为特定窗口使用 js.erb View 而不是 html.erb View 。这在实践中很好用,但是当我对 capybara 使用 cucumber 测试时,它给我一个错
我尝试使用 rails-erb-loader。 在我的 home.component.ts import templateString from './home.component.html'; 我有
我刚刚花了最后一个小时浏览 Atom 论坛寻找答案。有没有人想通了? 最佳答案 core: customFileTypes: "text.html.ruby": [
我没能找到讨论 create.js.erb 和 destroy.js.erb 如何适合 Rails 3 应用程序的文档。 app > Controller 中这些类型的 Javascript 文件背后
我目前正在尝试将 vue.js v-model 包含到我的 erb 表单输入标签中,但我找不到正确的语法。 这是我的代码目前的样子: 如果有任何想法,我将不胜感激。谢谢! 最佳答案 试试这
我是一名优秀的程序员,十分优秀!