我有一个简单的Cells示例,我想与Devise和Rails集成。但是,所有示例和问题似乎都适用于单元格3.以下内容在我的应用程序中失败(添加了行号)。
line 1: class UserCell < Cell::ViewModel
line 2: include Devise::Controllers::Helpers
line 3:
line 4: def index
line 5: render
line 6: end
line 7: end
为第2行引发此错误。
undefined method `helper_method' for UserCell:Class
答案 0 :(得分:2)
事实证明,默认情况下,Cell不再配置为与Rails一样工作(通过Cell :: Rails)。我不得不添加抽象控制器助手,但这让我自动在我的单元格中找到了所有设计助手。
class UserCell < Cell::ViewModel
include AbstractController::Helpers
include Devise::Controllers::Helpers
def index
render
end
end
答案 1 :(得分:1)
另一种方法是
// circuit -- circuit simulator
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// command parsing control
// NOTE: this can be build up if desired
struct cmd {
const char *cmd_str; // command string
const char *(*cmd_parse)(struct cmd *); // command parse function
};
// forward declarations
const char *parse_inputvar(struct cmd *cmd);
const char *parse_outputvar(struct cmd *cmd);
const char *parse_and(struct cmd *cmd);
const char *parse_or(struct cmd *cmd);
// list of supported commands
struct cmd cmdlist[] = {
{ .cmd_str = "INPUTVAR", .cmd_parse = parse_inputvar },
{ .cmd_str = "OUTPUTVAR", .cmd_parse = parse_outputvar },
{ .cmd_str = "AND", .cmd_parse = parse_and },
{ .cmd_str = "OR", .cmd_parse = parse_or },
{ .cmd_str = NULL }
};
int
main(int argc,char **argv)
{
FILE *circuit;
char line[5000];
char *cp;
struct cmd *cmd;
const char *err;
--argc;
++argv;
circuit = fopen(*argv, "r");
while (1) {
cp = fgets(line, sizeof(line), circuit);
if (cp == NULL)
break;
cp = strchr(line,'\n');
if (cp != NULL)
*cp = 0;
cp = strtok(line," ");
err = NULL;
for (cmd = cmdlist; cmd->cmd_str != NULL; ++cmd) {
if (strcmp(cp,cmd->cmd_str) == 0) {
err = cmd->cmd_parse(cmd);
break;
}
}
if (cmd->cmd_str == NULL)
printf("unknown command -- '%s'\n",cp);
if (err != NULL)
printf("error in %s command -- %s\n",cmd->cmd_str,err);
}
fclose(circuit);
}
const char *
parse_inputvar(struct cmd *cmd)
{
char *cp;
char *sym;
int cnt;
int idx;
const char *err = NULL;
do {
// get the count string
cp = strtok(NULL," ");
if (cp == NULL) {
err = "missing count";
break;
}
// decode count string into number
cnt = atoi(cp);
if (cnt <= 0) {
err = "bad count";
break;
}
for (idx = 0; idx < cnt; ++idx) {
sym = strtok(NULL," ");
if (sym == NULL) {
err = "missing symbol";
break;
}
// NOTE: sym will be invalid after we return so we need to preserve
// it now
sym = strdup(sym);
// do whatever ...
}
} while (0);
return err;
}
const char *
parse_outputvar(struct cmd *cmd)
{
const char *err = NULL;
return err;
}
const char *
parse_and(struct cmd *cmd)
{
const char *err = NULL;
return err;
}
const char *
parse_or(struct cmd *cmd)
{
const char *err = NULL;
return err;
}
您可以将所有内容委托给控制器
还有一种方法,特别是如果你想让你的单元格和控制器彼此独立,你可以在options {} hash中将对象和属性传递给你的单元格。