开发者

Multiple non-related models in one Rails form

I am building a blog-style application in Rails 3 where multiple users are able to post some news. After the login (which is realized with "Authlogic") the user values are stored in a own model called e.g. "UserSession". The form for the post contains title, content etc. and the username should be stored with a hidden form.

I think that the two models don't need to be related to each o开发者_开发问答ther (by that I mean a :has_many - :belongs_to relationship) because there isn't any further usage for that information.

Do I really not need this relation? And how could I realize the form?


For Authlogic is it important to remember that the 'UserSession' does not correspond to any database tables (i.e. you would never use a has_many or has_one 'UserSession'). I think the relationship you are looking for is:

User has many Posts
Blog belongs to User

The reason? It is always a good idea to associate a record with the 'owner' so that the owner can later modify or delete the record. I hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜