I'm creating a little widget that allows people to call recipes "favorites". But when they add a recipe, I don't want them to see the "Add as a favorite" button, I want them to see a "Remove from your favorites" link. I'm not sure what I need to do in the controller to make this happen. Here's what I have right now:
recipes_controller.rb:
def favorite Recipe.find(params[:id]).favorites.create(params[:favorite]) flash[:notice] = "You have added this recipe to your favorites." redirect_to :action => "show", :id => params[:id] end
show.rhtml:
<%= form_tag :controller => "recipes", :action => "favorite", :id => @recipe %> <%= hidden_field "favorite", "user_id", :value => current_user.id %> <%= submit_tag "Add as favorite", :class => "favorite" %> </form>
and I want to replace it with:
<%= link_to 'Un-favorite this recipe', :controller => "recipes", :action => "unfavorite", :recipe_id => @recipe, :user_id => current_user.id %>
In show.rhtml...
<% if params[:action] == 'favorite' %> ...put your un-favorite stuff here... <% else %> ...put your add as favorite stuff here... <% end %>