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:
flash[:notice] = "You have added this recipe to your favorites."
redirect_to :action => "show", :id => params[:id]
<%= form_tag :controller => "recipes", :action => "favorite", :id =>
<%= hidden_field "favorite", "user_id", :value => current_user.id %>
<%= submit_tag "Add as favorite", :class => "favorite" %>
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 %>
<% if params[:action] == 'favorite' %>
...put your un-favorite stuff here...
<% else %>
...put your add as favorite stuff here...
<% end %>