在我的视图中,我使用一个将任意HTML作为块的帮助器:
<% some_block_helper do %>
Some arbitrary HTML and ERB variables here.
More HTML here.
<% end %>
Run Code Online (Sandbox Code Playgroud)
在将其渲染回视图(Markdown和其他格式化)之前,我的助手会对传递的HTML块执行大量操作.我想知道在rSpec中测试helper调用结果的最简洁方法是什么,如果有的话.我发现了一些与ERB私有方法有关的例子,但这看起来有点脆弱,难以阅读.
我正在使用文本助手的truncate方法,这样做意味着正在呈现文本中包含的任何html.有没有设置文本助手去除html标签?
echo $text->truncate(
$project['Project']['description'],
250,
array(
'ending' => '...',
'exact' => false
)
);
Run Code Online (Sandbox Code Playgroud)
是否有类似stripLinks方法的修改?
谢谢,
Jonesy
我的选择表单工作正常,但无论参数的变化或排列如何,我的标签都不会显示.
这是我的代码:
<?php echo $this->Form->input('plan_detail_id', $plans_list, array(
'type' => 'select',
'label' => 'Select a the Plan Detail',
'empty' => '-- Select a the Plan Detail --'
)); ?>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我有第二个参数$plan_list,通常是label标签的位置.例如,我的所有其他标签都可以:
<td><?php echo $this->Form->input('age_id', array(
'label' => 'Select an Age Range',
'empty' => '-- Select an Age Range --'
)); ?></td>
Run Code Online (Sandbox Code Playgroud)
注意:没有$argument像第一个例子那样的第二个例子.我做错了吗?或者这不可能或是一个错误?
有没有人使用jsp调试帮助页面,可以将其放入任何webapp或从另一个jsp页面中包含,以查看标题,请求和会话属性?
如果可能,请你分享一下吗?对许多人来说,这将是一个很大的帮助
我创建了一个API访问库,我为库使用的常用函数创建了一个单独的帮助器.在codeigniter中,新库可以通过使用...创建自己的实例来访问本机类.
$ example_instance =&get_instance();
我做了这个,加载了我的助手 - 但每次调用辅助函数时,我都会得到"试图访问非对象"错误.我究竟做错了什么?
这就是我所拥有的
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class api_example {
private $api;
public function __construct(){
$this->api = & get_instance();
$this->api->load->helper('helper_test');
}
public function search_recent($param){
$string = $this->api->helper_test->connect($url); //error!!!
return $xml;
}
}
/* End of file */
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cakePHP Form帮助器显示内联构建的表单元素.它似乎与它围绕元素创建的类有关.我确信这可以用CSS修复,但如果有另一种方式我宁愿做正确的事:
<?php
echo $this->Form->create("users");
echo $this->Form->input("username",array("label" => false, "class" => false, "value" => "Username", "class" => "loginCredentials"));
echo $this->Form->input("password",array("label" => false, "class" => false, "value" => "Password", "class" => "loginCredentials"));
echo $this->Form->input("loginBtn",array("label" => false, "class" => false, "value" => "LOGIN", "class" => "loginCredentials", "type" => "submit"));
echo $this->Form->end();
?>
Run Code Online (Sandbox Code Playgroud) 我有一个Ember.Handlerbars.JSON帮助器,它将给定值格式化为缩进的JSON字符串.我想设置textarea的内容(值),如下所示:
{{#view Ember.TextArea}}
{{JSON someValue}}
{{/view}}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为我应该设置textareas的"值"属性.
但是,这也不起作用
{{view Ember.TextArea valueBinding="JSON someValue"}}
Run Code Online (Sandbox Code Playgroud) 我更多地讨论了如何向MAVEN添加更多源文件夹,我选择使用MOJO的build-helper-maven-plugin插件.该pom.xml的是这样的:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.maven.tests</groupId>
<artifactId>helper</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-gen-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src-gen/gen/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-extra-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/extra/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<includes>
<include>src/main/java/**/*.java</include>
<include>src-gen/gen/java/**/*.java</include>
<include>src/extra/java/**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
使用该命令mvn clean compile,构建完成正常,没有错误,但不生成任何类.
我确信我做错了但我无法弄明白.
我Api::V1::UsersController在app/controllers/api/v1中有一个控制器.我Api::V1::ErrorHelper在app/helpers/api/v1中有一个帮助模块.
我想访问控制器内的辅助模块的方法.所以,我调用了控制器的辅助方法,将模块传递给它:
class Api::V1::UsersController < ApplicationController
helper Api::V1::ErrorHelper
#other code
end
Run Code Online (Sandbox Code Playgroud)
但是当我访问控制器内部的一个辅助方法(respond_with_error)时,我得到以下异常:
undefined method `respond_with_error' for #<Api::V1::UsersController:0x007fad1b189578>
Run Code Online (Sandbox Code Playgroud)
如何从控制器访问此帮助程序?
(我使用的是Rails 3.2)
谢谢.
我正在尝试通过rspec在视图助手中设置局部变量。我的例行如下
def time_format(time)
now = Time.now.in_time_zone(current_user.timezone)
end
Run Code Online (Sandbox Code Playgroud)
我的规格文件如下:
it 'return 12 hour format' do
user = User.first
assign(:current_user, user)
expect(helper.time_format(900)).to eq('9:00 AM')
end
Run Code Online (Sandbox Code Playgroud)
规范失败并抛出错误未定义的局部变量或方法“ current_user”
“ current_user”驻留在application_controller中