简体   繁体   English

使用多个复选框更改一个字段-Rails控制器更改参数

[英]Use multiple checkboxes to change one field - rails controller change params

I've got articles that can be shown in lots of different sites. 我有可以在许多不同站点上显示的文章。 They can either be visible or not. 它们可以可见或不可见。

I've ended up going for a single bitmasked permission field in the article, rather than lots of has_many permissions separate records. 我最终在文章中只使用了一个位屏蔽的权限字段,而不是大量的has_many权限单独的记录。

I'm not sure how best to set this field. 我不确定如何最好地设置该字段。 What I've done so far is write two methods in the article model - one gives you a hash of {1 => 'true', 2 => 'true', 3 => 'false'} - visible or not on site 1, 2, 3 . 到目前为止,我已经在文章模型中编写了两种方法-一种为您提供{1 => 'true', 2 => 'true', 3 => 'false'}的哈希值-在站点上可见或不可见1, 2, 3 The second method takes a similar hash and sets the permission field correctly. 第二种方法采用类似的哈希,并正确设置权限字段。

I can send the permission hash to my view through the controller, and I can make checkboxes that show if the article is visible or not. 我可以通过控制器将权限哈希发送到我的视图,并且可以使复选框显示文章是否可见。 These appear on a pop up dialog using jquery. 这些出现在使用jquery的弹出对话框中。 I haven't done it yet, but I think I can use javascript to make a hash to send back. 我还没有完成,但是我想我可以使用JavaScript进行哈希发送。

But I don't know how to make the update controller take the hash from the params, send it to my make permission method and then put that into the params again to update my article. 但是我不知道如何使更新控制器从参数中获取哈希,将其发送到我的make许可方法,然后再次将其放入参数中以更新我的文章。

How would I go about doing this? 我将如何去做呢? Or am I barking up the wrong tree entirely. 还是我完全把错误的树都吠了。

Any ideas? 有任何想法吗?

I would suggest you to create a Site model which reproduces the different sites. 我建议您创建一个复制不同站点的Site模型。 This is especially a good thing if there might come up more websites! 如果可能会有更多的网站,这尤其好! Then you could build a has_and_belongs_to_many association between the Site and the Article model to commit on which site an article should be displayed! 然后,您可以在SiteArticle模型之间建立has_and_belongs_to_many关联,以承诺应该在哪个站点上显示文章!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM