我想知道是否有办法在使用CakePHP的$ form-> inputs()创建的表单中指定日期格式; 请注意,这不是单独的$ form-> input(),而是$ form-> inputs(),它将自动创建整个表单字段.
任何输入将不胜感激.谢谢.
当使用带有rspec测试的助手类时,我看不到使用这个.should be_false成语.在helper .rb文件中定义的函数中没有问题,但是当它在类中时,be_false找不到符号.以下示例 - 为什么这不起作用?我如何be_false在助手中使用et al?
似乎有可能这样的断言只能在测试中起作用.我有帮助因为例如因故障而失败.网络通信问题实际上是真正的测试失败,因为我的帮助者使用的网络通信是被测系统的一部分.我应该如何让我的测试在helper类中优雅地失败?
结果
$ spec ./test.rb
helper_foo 1
helper_foo 2
helper_foo 3
FunctionFoo 1
F
1)
NameError in 'my_test should test that helper classes can use should be_false etc'
undefined local variable or method `be_false' for #<HelperFoo:0x2b265f7adc98>
./helper.rb:13:in `FunctionFoo'
./test.rb:13:
Finished in 0.004536 seconds
1 example, 1 failure
Run Code Online (Sandbox Code Playgroud)
test.rb
require "helper.rb"
describe "my_test" do
it "should test that helper classes can use should be_false etc" do
(1 == 1).should …Run Code Online (Sandbox Code Playgroud) 我需要实现一个创建<button>...</button>标记的帮助器,我需要做一些类似的事情:
<%= form_for(some_var) do |f| %>
<%= f.submit '+' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
帮助器应该像这样工作:
<%= f.button '+' %>
# Returns
<button type="submit">+</button>
Run Code Online (Sandbox Code Playgroud)
我看到了https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/form_tag_helper.rb#L458,但这在Rails 3.0.7中没有实现.
我需要做什么才能在我的应用程序中实现这个帮助器?
如何在模块中调用另一个模块的帮助程序?
当我尝试
法师::助手( '助手类') - > getValueClass( '',$ ID)
它给了我错误:
致命错误:在第516行的C:\ wamp\www\example\app\Mage.php中找不到类'Mage_Helperclass_Helper_Data'
帮助程序类名称为Test_Helperclass_Helper_Data.
所以我正在使用zend-framwork创建一个项目,我正在尝试实现flash messenger助手,但我找不到任何好的实践来实现它.我需要的是使用flash messenger发送消息和重定向,而消息将直接出现在layout.phtml中的特定位置.我知道,对于重定向器,我可以这样做:
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl('/my-controller/my-action/param1/test/param2/test2')
->redirectAndExit();'
Run Code Online (Sandbox Code Playgroud)
我可以对闪光灯消息器做些什么来使其工作?那是什么最好的做法?
我有很多实用工具方法(例如用于重新格式化或解析诸如字符串之类的简单对象)的方法,我一直将它们放在ApplicationHelper中。
但是,显然模型中的类方法无法访问ApplicationHelper方法。
有一个解决方法,可以在我的整个项目中使用:
include ApplicationHelper # needed to use apphelper method in instance method
extend ApplicationHelper # needed to use apphelper method in class method
Run Code Online (Sandbox Code Playgroud)
而且似乎可行。但这似乎是一种矛盾。
有没有更好的放置实用程序方法的地方,以便可以从项目的任何位置访问它们-视图,控制器方法,模型实例方法,模型类方法?
如果这是一个愚蠢的问题我很抱歉,但我是OCaml的新手,我无法在任何地方找到这方面的例子.有人能给我一个简单的Ocaml语法示例,用于在另一个函数中定义辅助函数吗?
谢谢!
请告诉我如何从自定义模板中包含帮助文件?
例如,我想从/modules/mod_breadcrumbs/helper.php获取ModBreadCrumbsHelper类
在自定义模板/templates/test/html/com_content/article/default.php中
使用Devise与Omniauth我成功地允许用户使用他们的Facebook帐户登录.在Omniauth wiki的帮助下,我还可以禁用在编辑帐户时输入密码.
我遇到的当前问题是registrations#edit如果他们通过Facebook注册了我的密码字段.作为两个宝石的新手我还在努力调整.因此,在设置必要的辅助方法时,我有点不知所措.
根据维基的指示,这是我的注册控制器的样子:
class RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters, if: :devise_controller?
def update
@user = User.find(current_user.id)
successfully_updated = if needs_password?(@user, params)
@user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
else
# remove the virtual current_password attribute
# update_without_password doesn't know how to ignore it
params[:user].delete(:current_password)
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
end
if successfully_updated
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
private
# check if we need password …Run Code Online (Sandbox Code Playgroud) 说我有一个功能:
arbitrary :: String -> String -> Maybe String
arbitrary st1 st2 | (st1 == st2) = Just "foo"
| (arbitrarily_complex_calculation == 7) = Nothing
| otherwise = Just $ show arbitrarily_complex_calculation
Run Code Online (Sandbox Code Playgroud)
如何在两个保护块之间共享任意complex_calculation?这可以通过let/ where或者我必须编写辅助函数来完成吗?