相关文章
更多最近更新
更多如何在javascript中写rails的helper代码
2019-03-25 13:37|来源: 网路
如果在模板中这样写
到了页面中就变成了:
显然不对了,怎么写才好?
当然可以不写helper,而直接在javascript中按后面的内容来写。
我是想问可不可以按helper来写?
<SCRIPT language=JavaScript> var str = '<%= link_to_remote("ddddddddd", :update => "page_space_1",:url => {:action => :new}) %>' </SCRIPT>
到了页面中就变成了:
<SCRIPT language=JavaScript> var str = '<a href="#" onclick="new Ajax.Updater('page_space_1', '/admin/welcome/new', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('Wm0NEEnaKCjLKNHYcS1u6e56HqzeQnT+UfIay/GaOek=')}); return false;">ddddddddd</a>' </SCRIPT>
显然不对了,怎么写才好?
当然可以不写helper,而直接在javascript中按后面的内容来写。
我是想问可不可以按helper来写?
相关问答
更多-
您可以使用send("edit_user_path")替换edit_user_path 。 已在控制台中验证。 现在你可以在里面插入字符串了。 You can replace edit_user_path with send("edit_user_path"). Already verified in console. Now you can interpolate the string inside.
-
对于Rails <3.0 运行script/console --help 。 您会注意到语法是script/console [environment] ,在这种情况下,它是script/console test 。 我不知道你是否需要测试帮助器,或者如果测试环境为你做,那么你应该能够成功启动测试环境。 作为旁注:脚本中的各种二进制文件具有不同的设置轨道环境的方法确实有点奇怪。 对于Rails 3和4 运行rails c test 。 如果您需要此应用程序环境,请准备好bundle exec 。 For Ra ...
-
您可以在erb模板中包含任何帮助/模块/类: <% environment.context_class.instance_eval { include MyHelper } %> 请参阅: https : //github.com/sstephenson/sprockets/blob/master/lib/sprockets/environment.rb和https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/context.r ...
-
我把帮助器包含在我的黄瓜测试中的方式: 您在支持文件夹下创建文件world.rb(或任何您想要的名称)。 在我的world.rb中我定义如下: module Helper include ProjectHelper include ProductBacklogHelper include ApplicationHelper include Capybara::DSL include Prickle::Capybara end #end Module World(Hel ...
-
只需在您的视图中编写javascript,并在适当的位置将@selected_items数组打印为json: app/views/*/*.html.erb 如果to_json不能序列化更复杂的对象,也可以使用Gon宝石。 Just write the javascript in your vie ...
-
我如何在主应用程序中访问Rails可挂载引擎辅助方法?(How can I access Rails mountable engine helper method in main app?)[2021-10-14]
最后我找到了解决方案,这里是我的发现:) 用于访问rails挂载引擎的辅助方法将这些行添加到可挂载引擎的lib/my_engine/engine.rb文件中 config.before_initialize do ActiveSupport.on_load :action_controller do helper MyEngine::Engine.helpers end end Finally i found a solution for this and here is my findi ... -
form_for采取一个块,所以它更像。 如果此记录与该资源相同,则不需要:url选项。 FormHelper检查@myrecord是否为#new_record? 或不。 如果new_record使用POST而不是使用PUT。 <% form_for @myrecord do |f| %> <%= f.text_field :field %> <% end %> form_for take a block so it's more like. If this record is same tha ...
-
如何在Rails 4应用程序中向form_for帮助器添加一个类?(How to add a class to the form_for helper in a Rails 4 app?)[2024-03-24]
你可能得到了答案,虽然这些点可能对你有帮助 带有haml类名的form_for: = form_for @patient, :html => {:class => "form-horizontal"} do |f| 它也可以写成 = form_for @patient, {:html => {:class => "form-horizontal"}} do |f| 但它不能写成 - form_for @patient, :html => {:class => "form-horizontal"} do ... -
请检查文件 config/environments/development.rb config.assets.debug = true(如果TRUE更改为FALSE) Please check the file config/environments/development.rb config.assets.debug = true (if TRUE change to FALSE)
-