Reputation: 599
I want to be able to use a PUT request to edit the title of a song I uploaded in my Ruby on Rails application.
def update
@sound_byte = SoundByte.find(params[:id]) #Error here
@sound_byte.update!(sound_byte_params)
flash[:success] = "The soundbyte title was changed."
redirect_to sound_byte_path
end
private
def sound_byte_params
params.require(:sound_byte).permit(:mpeg, :mpeg_file_name)
end
I end up getting an error like this:
Couldn't find SoundByte with 'id'=song_name
Any ideas of how to fix this issue? I am using the Paperclip gem to enable the audio/mpeg file uploads.
EDIT: Here is my views code
<%= link_to "Edit", sound_byte_path(sound_byte.mpeg_file_name), class: "btn btn-primary btn-lg btn-xlarge", :method => :put %>
Upvotes: 0
Views: 1078
Reputation: 748
In the view page, you pass string sound_byte.mpeg_file_name
as params, but in your controller, you use id @sound_byte = SoundByte.find(params[:id])
.
Try this
<%= link_to "Edit", sound_byte_path(sound_byte.id), class: "btn btn-primary btn-lg btn-xlarge", :method => :put %>
Upvotes: 1