Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= form_with scope: :track, local: true do |t| %>
- <p>
- <%= t.text_field :name %>
- </p>
- <p>
- <%= t.text_area :description %>
- </p>
- <p>
- <%= t.text_field :genre %>
- </p>
- <p>
- <%= t.file_field :audiofile %>
- </p>
- <p>
- <%= t.submit %>
- </p>
- <% end %>
- class TracksController < ApplicationController
- before_action :set_track, only: [:show, :update, :destroy]
- def index
- @tracks = Track.all
- json_response(@tracks)
- end
- def new
- @track = Track.new
- end
- def find_by_genre
- @tracks = Track.where(genre: [params[:genre]])
- json_response(@tracks)
- end
- def create
- @track = Track.create!(track_params)
- json_response(@track, :created)
- end
- def show
- json_response(@track)
- end
- def update
- @track.update(track_params)
- head :no_content
- end
- def destroy
- @track.destroy
- head :no_content
- end
- private
- def track_params
- params.permit(:name, :description, :genre, :audiofile, :created_by)
- end
- def set_track
- @track = Track.find(params[:id])
- end
- end
- <%= form_with scope: :track, local: true do |t| %>
- <%= form_with url: tracks_path do |form| %>
Add Comment
Please, Sign In to add comment