Guest User

Untitled

a guest
Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <%= form_with scope: :track, local: true do |t| %>
  2. <p>
  3. <%= t.text_field :name %>
  4. </p>
  5.  
  6. <p>
  7. <%= t.text_area :description %>
  8. </p>
  9.  
  10. <p>
  11. <%= t.text_field :genre %>
  12. </p>
  13.  
  14. <p>
  15.    <%= t.file_field :audiofile %>
  16. </p>
  17.  
  18. <p>
  19. <%= t.submit %>
  20. </p>
  21. <% end %>
  22.  
  23. class TracksController < ApplicationController
  24. before_action :set_track, only: [:show, :update, :destroy]
  25.  
  26. def index
  27. @tracks = Track.all
  28. json_response(@tracks)
  29. end
  30.  
  31. def new
  32. @track = Track.new
  33. end
  34.  
  35. def find_by_genre
  36. @tracks = Track.where(genre: [params[:genre]])
  37. json_response(@tracks)
  38. end
  39.  
  40. def create
  41. @track = Track.create!(track_params)
  42. json_response(@track, :created)
  43. end
  44.  
  45. def show
  46. json_response(@track)
  47. end
  48.  
  49. def update
  50. @track.update(track_params)
  51. head :no_content
  52. end
  53.  
  54. def destroy
  55. @track.destroy
  56. head :no_content
  57. end
  58.  
  59. private
  60. def track_params
  61. params.permit(:name, :description, :genre, :audiofile, :created_by)
  62. end
  63.  
  64. def set_track
  65. @track = Track.find(params[:id])
  66. end
  67. end
  68.  
  69. <%= form_with scope: :track, local: true do |t| %>
  70.  
  71. <%= form_with url: tracks_path do |form| %>
Add Comment
Please, Sign In to add comment