Rails:使用变量创建记录

发布于 2024-11-28 14:46:08 字数 269 浏览 2 评论 0原文

我想要 4 组不同的数据: 创造, 更新, 我想使用

变量对每个函数使用一个操作,但无法使其工作。

例如:

def create

@type = params['type']   # use an outside ajax request to decide type
@type.create(:title => 'new title')  # create a new table using that type

end

I have 4 different groups of data that I want to:
create,
update,
delete

I want to use one action for each function, using a variable, but can't get it to work.

For example:

def create

@type = params['type']   # use an outside ajax request to decide type
@type.create(:title => 'new title')  # create a new table using that type

end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过气美图社 2024-12-05 14:46:08

您尝试过constantize吗?

def create
  @type = params['type'].constantize   # use an outside ajax request to decide type
  @type.create(:title => 'new title')  # create a new table using that type
end

Have you tried constantize?

def create
  @type = params['type'].constantize   # use an outside ajax request to decide type
  @type.create(:title => 'new title')  # create a new table using that type
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文