开发者

Create post page, how to create a list of checkboxes with tags, and create action?

I have a Post that ha开发者_Python百科s many tags.

In the form when creating a new post, I want to display a list of tags with checkboxes, and a input textbox where someone can type in a new tag name.

When the form is submitted, it saves the post, and then associates the tags (either selected form a checkbox and/or entered in the new tag input textbox.

Can someone help me with how I should do this in my view and create method?


What do you want to do in the view?

In the view, you'll just have your form. Since there is 2 models in one form, you should use fields_for http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for to separate them.

Then in your controller, probably in the edit action of the posts controller, you'll have to get the tags from the text field, create them if they dont exists and associate them to your post object. You can use helper methods for stuff like extracting the tags name from the user input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜