在很多框架/ AMS/CMS中,我看到了"helper"脚本和类的文件夹.帮助程序脚本和类到底做了什么?他们的具体目的是什么?这是由开发人员定义的还是他们的功能标准?
这是输入HTML:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat …Run Code Online (Sandbox Code Playgroud) 这就是我在我的erb.js文件中所拥有的....但它不起作用:
1 //Update with a message
2 $('#follow-update').html("<%= follow_button(@question) %>")
Run Code Online (Sandbox Code Playgroud)
follow_button是一个帮手:
20 def follow_button(resource)
21
22 type = resource.class.name
23 follow_status = current_user.following?(resource)
24
25 verb = "Follow" if follow_status == false
26 verb = "Unfollow" if follow_status == true
27
28 content_tag(:div, :class => "follow-button") do
29 link_to "#{verb} this #{type} ", follow_path(:followed_type => type,
30 :followed_id => resource.id,
31 :follow_verb => verb),
32 :class => "button",
33 :remote => true
34 end
35 end
36 end
Run Code Online (Sandbox Code Playgroud)
帮助程序独立工作正常,但我希望它更新我的按钮.也许有一种方法可以在不更换整个助手的情况下更新文本?
我试图通过使用razor的@:运算符将一些Html传递给辅助方法,但我无法弄清楚如何做到这一点.编译器声明Razor表达式是一个lambda表达式,但它没有说,这个lambda表达式是什么样的......根本就没有线索!
如果我尝试这样做:
@(MyClass.MyMethod(new
{
Html = @:<div></div>
}
))
Run Code Online (Sandbox Code Playgroud)
错误如下:
Cannot assign lambda expression to anonymous type property
如果我尝试这样做,那么它再次声明它是一个lambda:
@(MyClass.MyMethod(
@:<div></div>
))
Run Code Online (Sandbox Code Playgroud)
如果MyMethod收到一个字符串:ie public string MyMethod(string razorConstructedString)
,那么编译器说:Cannot convert lambda expression to type 'string' because it is not a delegate type.
问题是:我应该声明什么类型的MyMethod,以便它可以接收剃刀构造的参数?
谢谢!
我在Rails 3中调用Rails控制台中的辅助方法,如下所示:
>> helper.my_method(parameter)
>> #=> some result
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改辅助方法,则当我再次调用相同的方法时,不会反映更改.我必须exit运行rails console以便看到辅助方法的更改生效.
我知道这很简单,但我不记得怎么做,而且无法在Google上找到它......
我很少需要一个特定于控制器的帮助文件,所以我希望当我生成一个Controller时,不会随之生成帮助程序(和帮助程序规范).
我试过了
#application.rb
config.generators do |g|
g.helpers false
end
Run Code Online (Sandbox Code Playgroud)
......但那没用.你怎么改变它?
我正在尝试使用辅助模块中的方法,但rspec似乎没有识别出测试的助手spec/features.请注意,唯一的变化spec_helper.rb是添加require 'capybara/rspec'.
我尝试移动helper.rb到spec/support,spec/helpers和spec/features(包含我的测试的目录),但没有运气.测试始终指示辅助方法未定义.
让它"工作"的唯一方法是将我的测试移动到另一个目录,例如spec/integration.但现在水豚将无法工作(visit undefined)因为它不在spec/features.
这是我的助手模块(authentication_helper.rb):
module AuthenticationHelper
def sign_in_as!(user)
visit '/users/sign_in'
fill_in "Email", with: user.email
fill_in "Password", with: "password"
click_button "Sign in"
page.should have_content("Signed in successfully.")
end
end
RSpec.configure do |c|
c.include AuthenticationHelper, type: :request
end
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的帮手:
if current_user.find_voted_items(vote_scope: :inspired).include?(post)
link_to vote_inspired_post_path(post, vote_scope: :inspired), method: :post, data: { confirm: 'Are you sure this post Inspires you?' }, class: "btn btn-default" do
"<i class='fa fa-lightbulb-o'></i> <br />Inspired".html_safe
end
link_to vote_happy_post_path(post, vote_scope: :happy), method: :post, data: { confirm: 'Are you sure this post makes you happy?' }, class: "btn btn-success" do
"<i class='fa fa-smile-o'></i> <br />Happy".html_safe
end
link_to vote_disappointed_post_path(post, vote_scope: :disappointed), method: :post, data: { confirm: 'Are you sure this post disappointed you?' }, class: "btn btn-info" do …Run Code Online (Sandbox Code Playgroud) class ClassLoaderHelper {
private ClassLoaderHelper() {}
static File mapAlternativeName(File lib) {
return null;
}
Run Code Online (Sandbox Code Playgroud)
我没有发现任何mapAlternativeName无法覆盖的用法(静态)
还评论没有实际意义
Run Code Online (Sandbox Code Playgroud)/** * Returns an alternate path name for the given file * such that if the original pathname did not exist, then the * file may be located at the alternate location. * For most platforms, this behavior is not supported and returns null. */
它是从以前的版本中遗留下来的,还是仅用于将来使用的指定Helper类?
编辑
我发现一个相关的错误(解决方案:未解决)JDK-7157665:对所有本机库加载使用ClassLoaderHelper
需要更新7134701的修复程序,以对加载本机库的其他代码路径进行相同的更改:即-使用非引导类加载器的地方和-调用System.load()的地方
在这两种情况下,都提供了绝对路径名,但是(在Mac上)我们应该尝试首先加载原始文件,在Mac上,为了与Apple的jdk 6兼容,我们应该寻找.jnilib变体(如果原始名称为*)。 dylib,但找不到。