I have a page that I'm rendering through the index action of a controller. I want to add a link to this page, which will reload the current page, but I want it to route to a different action first.
Here's what my routes.rb file looks like:
match 'users/:id/food' => 'foods#index', :as => :foods_show
match 'users/:id/food' => 'foods#sell', :as => :food_sell
And my link_to:
<%= link_to "Sell this Food", food_sell_path(current_user.id) %>
So the page is normally rendered via foods#index, but when a User clicks on this link, I want to reload the current page but via a different action than index.
Controller code:
def index
@user = User.find(params[:id])
@food = @user.foods
end
def sell
@user = User.find(params[:id])
@food = @user.foods
redirect_to foods_show_path(@user.id), :notice => "You have sold one item!"
end
Thanks!