I'm beginner at Rails, and im actually stuck with apparently a "beginner problem".
I got a "sounds" scaffolded controller, and i had to add an action "sendit". I can't have access to the sound from my view to my controller.
This is my error when i try to access to "http://127.0.0.1:3000/sounds/sendit.14" (Why it's sendit.14 and not sounds/sendit/14 or sounds/14/sendit ?)
ActiveRecord::RecordNotFound in SoundsController#sendit
Couldn't find Sound without an ID
Application Trace | Framework Trace | Full Trace
app/controllers/sounds_controller.rb:74:in `sendit'
Request
Parameters:
{"format"=>"14"}
Here is my code :
Sound Controller :
def sendit
@sound = Sound.find(params[:id]) # ----- Error is on this line -----
# Do Job
end
Index.html.erb
<% @sounds.each do |sound| %>
<% if sound.user_id == current_user.id %>
<tr>
<td><%= sound.title %></td>
<td><%= sound.user.email %></td>
<td><%= link_to 'Show', sound %></td>
<td><%= link_to 'Edit', edit_sound_path(sound) %></td>
<td><%= link_to 'Destroy', sound, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Send', sounds_sendit_path(sound) %></td>
routes.rb
devise_for :users
match "/sounds/sendit/", :controller => "sounds", :action => "sendit"
resources :users, :sounds
I did this in the route file because of Adding an action to an existing controller (Ruby on Rails)
When i do rake routes , this is the output :
[...]
sounds_sendit /sounds/sendit(.:format) sounds#sendit
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sounds GET /sounds(.:format) sounds#index
POST /sounds(.:format) sounds#create
new_sound GET /sounds/new(.:format) sounds#new
edit_sound GET /sounds/:id/edit(.:format) sounds#edit
sound GET /sounds/:id(.:format) sounds#show
PUT /sounds/:id(.:format) sounds#update
DELETE /sounds/:id(.:format) sounds#destroy
root / home#index
(I actually don't understand the first line, why there is no POST / GET, and why it's sounds_sendit and no sendit_sound like others default actions? How to fix it? )
Thank you for your help