第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在Rails 3和4中實(shí)施“添加到收藏夾”

在Rails 3和4中實(shí)施“添加到收藏夾”

慕的地6264312 2019-11-26 13:19:23
我正在構(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)為我可能在路線中缺少一些東西,但不確定。
查看完整描述

3 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

這個(gè)線程超級(jí)有幫助??!


謝謝!


不要忘記在表單標(biāo)簽中包含=。


<% if current_user %>

  <%=link_to "favorite",   favorite_recipe_path(@recipe, type: "favorite"), method: :put %>

  <%=link_to "unfavorite", favorite_recipe_path(@recipe, type: "unfavorite"), method: :put %>

<% end %>


查看完整回答
反對(duì) 回復(fù) 2019-11-26
  • 3 回答
  • 0 關(guān)注
  • 712 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)