Reputation: 11
I'm working on a project in Sinatra and I can't seem to get the delete method to work. My intent is to be able to remove an object using a form in a modal. Here's what I have:
routes.rb:
delete '/songs/:id/delete' do
@song = Song.where(:id => params[:id]).first
@song.delete
redirect to '/songs'
end
index.erb:
<form action="/songs/:id/delete" method="post">
<input type="hidden" name="_method" value="delete">
<div id="song_id">
<label>id:</label>
<input type="text" name="id">
</div>
<button type="submit" id="delete">Delete</button>
<a href="/songs"><div id="back">Back to Songs</div></a>
</form>
Feedback is appreciated. (Also, sorry indentation isn't perfect)
Upvotes: 1
Views: 321
Reputation: 45941
You have to inject the id into the form. Not :id
.
# example
<form action="/songs/1234/delete" method="post">
Also, you can see what is happening with puts params
.
Upvotes: 1