ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

Error on redirect_to :back within Favorites #905

Closed lizardbird closed 7 years ago

lizardbird commented 7 years ago

I think my favorites many-to-many is working, but when I click on the ♥, it throws a error.

undefined method `back_url' for #<BowlsController:0x007f96c7598c28>

I found guidance online that says redirect_to :back is deprecated and instead to use redirect_back fallback_location: root_path but neither are working for me. Any help? Thx in advance!

lizardbird commented 7 years ago

To clarify - I believe it is still working because when I manually go back to the post in question, the heart reflects the appropriate "favorited" status.

jsm13 commented 7 years ago

Hmm, I think that redirect_to :back might tell the browser to just use the last page that already loaded. See if:

  def remove_favorite
    bowl = Bowl.find(params[:id]
    Favorite.find_by(user: current_user, bowl: bowl).destroy
    redirect_to bowl
  end

helps

lizardbird commented 7 years ago

Yeah, that was the example used in the lesson on favorites and redirecting. Either way, I ended up trying bowl_path(@bowl) and that worked. Resolved!