我正在構(gòu)建一個(gè)應(yīng)用程序,用戶可以在其中創(chuàng)建配方,查看所有創(chuàng)建的配方,在成員區(qū)域中查看自己的配方,最后我希望用戶向其帳戶添加“收藏夾”。我是Rails的新手,但已經(jīng)閱讀了文檔,這是我對(duì)后端外觀的理解。如果我做錯(cuò)了事(可能是這種情況),可以請(qǐng)人確認(rèn)這看起來(lái)正確還是建議任何錯(cuò)誤,并附上解釋?zhuān)窟@是我的代碼:用戶模型has_many :recipeshas_many_favorites, :through => :recipes配方模型belongs_to :userhas_many :ingredients #created seperate db for ingredientshas_many :prepererations #created seperate db for prep steps最喜歡的模型belongs_to :userhas_many :recipes, :through => :user#this model has one column for the FK, :user_id收藏夾控制器def create @favrecipes =current_user.favorites.create(params[:user_id])end然后,我想有一個(gè)按鈕發(fā)布到數(shù)據(jù)庫(kù),所以我有這個(gè):<%= button_to("Add to Favorites" :action => "create", :controller => "favorites" %>我認(rèn)為我可能在路線中缺少一些東西,但不確定。
在Rails 3和4中實(shí)施“添加到收藏夾”
慕的地6264312
2019-11-26 13:19:23