Reputation: 553
I have written a submit_tag in my games/show.html.erb class and it is as followed:
<% form_tag game_path, :method => 'submit' do %>
<div class="actions"><%= submit_tag "Interested in trading", :name => 'confirm' %></div>
<% end %>
In my games_controller
under the show
method I have the following:
def show
@game = Game.find(params[:id])
if params['confirm']
respond_to do |format|
user = @game.user
email = user.email
g = GameTrade.game_interest(user)
g.deliver
format.html { redirect_to root_url }
format.json { render json: @game }
end
elsif
respond_to do |format|
format.html
end
end
end
Now the show page displays fine but when I click on the submit_tag
it does nothing and by nothing I mean it is dead you click on it and it does no action what so ever. Just a dummy. Any ideas what is wrong in my controller logic here?
Upvotes: 0
Views: 1562
Reputation: 16084
The problem is your view, not your controller.
Submit tags must be inside forms. When you click on it, they submit the form -- without a containing form, the submit tag is totally useless.
If you want just a button that leads to somewhere, try checking out button_to: it will create a submit tag and a form directed towards whatever action you specify.
Upvotes: 1