标签: helper

helper和helper_method做了什么?

helper_method 很简单:它使部分或全部控制器的方法可用于视图.

什么是helper?是否相反,即它将辅助方法导入文件或模块?(也许是名字helperhelper_method相似.他们可能更愿意share_methods_with_viewimport_methods_from_view)

参考

ruby-on-rails helper

196
推荐指数
1
解决办法
9万
查看次数

如何从rails模块访问URL帮助程序

我有一个带功能的模块.它位于/lib/contact.rb中:

module Contact
  class << self
    def run(current_user)
      ...
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我想访问模块中的'users_path'之类的URL帮助程序.我怎么做?

ruby url model ruby-on-rails helper

66
推荐指数
4
解决办法
4万
查看次数

46
推荐指数
2
解决办法
2万
查看次数

何时使用Helpers而不是Partials

在rails应用程序中,在哪种情况下你会使用partial,你什么时候会使用帮助器?我发现两者非常相似,因为它们代表了标记片段.

围绕这个有约定吗?使用它们的'轨道方式'是什么?

谢谢!

ruby-on-rails helper partials

45
推荐指数
3
解决办法
6352
查看次数

如何测试ApplicationController方法也定义为辅助方法?

在我的ApplicationController中,我有一个定义为辅助方法的方法:

helper_method :some_method_here

  • 我如何在RSpec中测试ApplicationController?
  • 在测试我的视图/帮助程序时,如何包含/调用此帮助程序方法?

我正在使用Rails3和RSpec2

rspec ruby-on-rails helper rspec2

44
推荐指数
2
解决办法
3万
查看次数

如何将类添加到image_tag rails helper

我有以下代码:

<%= image_tag iterator.image.url(:small), :class => "img_preview" %>
Run Code Online (Sandbox Code Playgroud)

但呈现的HTML显示:

<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452" alt="Clean_wave">
Run Code Online (Sandbox Code Playgroud)

为什么"class"属性不存在?

谢谢!

ruby-on-rails image helper lccs

44
推荐指数
2
解决办法
7万
查看次数

从Rails中的控制器调用helper方法时的"未定义方法"

有谁知道我为什么得到

undefined method `my_method' for #<MyController:0x1043a7410>
Run Code Online (Sandbox Code Playgroud)

当我从ApplicationController子类中调用my_method("string")时?我的控制器看起来像

class MyController < ApplicationController
  def show
    @value = my_method(params[:string])
  end
end
Run Code Online (Sandbox Code Playgroud)

和我的帮手

module ApplicationHelper
  def my_method(string)
    return string
  end
end
Run Code Online (Sandbox Code Playgroud)

最后,ApplicationController

class ApplicationController < ActionController::Base
  after_filter :set_content_type
  helper :all
  helper_method :current_user_session, :current_user
  filter_parameter_logging :password
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails helper helpers applicationcontroller

41
推荐指数
5
解决办法
7万
查看次数

(PartialView)传递到字典中的模型项的类型为"Customer",但此字典需要"UserProfile"类型的模型项

@model Customer

@Html.Partial("_UserProfile", (UserProfile)Model.UserProfile)
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我收到此错误:

The model item passed into the dictionary is of type 'Customer', but this dictionary requires a model item of type 'UserProfile'.
Run Code Online (Sandbox Code Playgroud)

部分视图_UserProfile是强类型的.

我希望能够编辑这些字段.有什么建议?

c# asp.net-mvc partial-views helper razor

40
推荐指数
2
解决办法
2万
查看次数

类名中的"助手"这个词是代码味吗?

我们似乎从网页中抽象了许多逻辑方式并创建了"帮助"类.可悲的是,这些课程听起来都是一样的,例如

ADHelper,(Active Directory)AuthenicationHelper,SharePointHelper

其他人是否有大量具有此命名约定的类?

language-agnostic naming class helper

38
推荐指数
4
解决办法
9724
查看次数

Helper是为了将非null属性从对象复制到另一个?(JAVA)

请参阅以下课程

public class Parent {

    private String name;
    private int age;
    private Date birthDate;

    // getters and setters   

}
Run Code Online (Sandbox Code Playgroud)

假设我已经创建了一个父对象,如下所示

Parent parent = new Parent();

parent.setName("A meaningful name");
parent.setAge(20);
Run Code Online (Sandbox Code Playgroud)

请注意,根据上面的代码,birthDate属性为null.现在我想从父对象复制到另一个非空属性.就像是

SomeHelper.copyNonNullProperties(parent, anotherParent);
Run Code Online (Sandbox Code Playgroud)

我需要它,因为我想更新anotherParent对象而不用空值覆盖其非null.

你知道这样的帮手吗?

我接受最少的代码作为答案是否没有帮助

问候,

java helper

37
推荐指数
3
解决办法
3万
查看次数