Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 轨道3。如何使用带in按钮标签的disable_?_Html_Ruby On Rails_Ruby - Fatal编程技术网

Html 轨道3。如何使用带in按钮标签的disable_?

Html 轨道3。如何使用带in按钮标签的disable_?,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,我最近开始测试web_应用程序_主题插件。在创建按钮,我有这样的东西 <button class="button" type="submit"> <%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Sav

我最近开始测试web_应用程序_主题插件。在创建按钮,我有这样的东西

<button class="button" type="submit">
  <%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Save") %>
</button>

“#{t(“web应用主题.save”,:default=>“save”)}”)%%>“save”)%%>
如何将
:使用=>“处理”禁用\u
添加到此按钮以防止重复记录


我尝试了
t(“web app theme.save”,:default=>“save”),:disable_with=>“Processing”
,但当然,这不起作用。

您需要使用表单标记帮助器方法-类似这样的方法应该可以做到:

<%= button_tag :class => "button", :type => "submit", :data => { :disable_with => "Processing" } do %>
  <%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> 
  <%= t("web-app-theme.save", :default => "Save") %>
<% end %>
“按钮”,:type=>“提交”,:data=>{:disable_with=>“处理”}do%>
“#{t(“web应用主题.save”,:default=>“save”)}”)%>
“保存”)%%>
这里有一个链接,指向
按钮\u到
方法的API文档:


Rails 3.2和4语法于2013年12月14日更新。

按钮标签是完全可选的。您可以按如下方式轻松地在html中编辑标记:

<button class="button" type="submit" data-disable-with="Processing">
  <%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%= t("web-app-theme.save", :default => "Save") %>
</button>

“#{t(“web应用主题.save”,:default=>“save”)}”)%%>“save”)%%>
:disable_with
所做的就是向元素添加一个data disable with属性。然后jquery rails gem的javascript(jquery_ujs.js)为您完成其余的禁用工作


当然,这是假设您使用的是rails 3.0或更高版本。

谢谢!只有一个编辑:按钮标签后面不应该有逗号。我试着编辑,但它告诉我,我必须编辑至少6个角色啊-是的,谢谢你抓住了这一点。我只是在疯狂地打字!这将被弃用吗?它没有弃用,但旧的实现是-我已经更新了答案,以包括新的语法。这是一个简单的更新,只需在
:data
散列中添加
:disable\u或
:confirm
之类的操作即可。我是否可以指定ajax处理完成后要显示的值,而不是在ajax之前重置为值?@Dean不能没有自己的javascript来设置所需的文本。当你说“ajax处理”时,这是否意味着你在使用
dataremote=true
?您应该能够执行类似于
$('button[type=submit]')的操作