SyntaxError in SongsController#index - ruby-on-rails

Not sure why I seem to be getting this error as I have the appropriate amount of ends. The app was working - and then I installed devise and it went to hell. I un-installed devise to go back to the working version but now I seem to be getting the error shown below.
Error msg
SyntaxError in SongsController#index
/Users/user/Sites/leap2/leap2/app/controllers/songs_controller.rb:13: syntax error, unexpected end-of-input, expecting keyword_end
Songs_controller.rb
class SongsController < ApplicationController
before_action :set_song, only: [:show, :edit, :update, :destroy]
def index
#songs = Song.all
end
def new
#song = Song.new
end
def show
end
def edit
end
def create
#song = Song.new(song_params)
respond_to do |format|
if #song.save
format.html { redirect_to #song, notice: 'Song was added successully'}
format.json {render action: 'show', status: :created, location: #song}
else
format.html { render action: 'new' }
format.json { render json: #song.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #song.update(song_params)
format.html {redirect_to #song, notice: 'Song was successfully updated.' }
format.json {head :no_content }
else
format.html {render action: 'edit' }
format.json {render json: #song.errors, status: :unprocessible_entity }
end
end
end
def destroy
#song.destroy
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end
private
def set_song
#song = Song.find(params[:id])
end
def song_params
params.require(:song).permit(:title, :artist, :bio, :track)
end
end
show.html.erb
<p id="notice"><%= notice %>
<p>
<strong>Title:</strong>
<%= #song.title %>
</p>
<p>
<strong>Bio:</strong>
<%= #song.bio %>
</p>
<p>
<strong>Audio:</strong>
<%= audio_tag (#song.track.url), controls: "controls" %>
</p>
<br /><br />
<%= link_to 'Edit', edit_song_path(#song), class: "button small secondary"%>
<%= link_to 'Back', songs_path, class: "button small secondary" %>
_form.html_erb
<%= form_for #song, :html => { :multipart => true } do |f| %>
<% if #song.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#song.errors.count, "error") %> prohibited this song from being saved:</h2>
<ul>
<% #song.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="large-6 columns">
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :bio %>
<%= f.text_area :bio %>
</div>
<p>
<%= f.file_field :track%>
</p>
<div class="actions">
<%= f.submit value: "Upload" %>
</div>
<% end %>
</div>
<div class="large-6 columns"><h3>Submit your own song or a personal favourite and watch it climb the charts! </h3>
</div>
</div>

in application_controller.rb you had one extra end.
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def authorize
redirect_to new_user_session_path, notice: "You have to be logged in to submit."
if current_user.nil?
end
end
end

Related

Rails app - extra record displaying

I have an app that allows users to add albums they like to a database. Anyone can then come along and write a review for that album. Pretty simple.
I am running into a problem where an extra record appears to be created for the reviews on each album's show page. Every album, even if it has not ever been reviewed, has an additional, seemingly empty review being displayed when I use .each to display each review in the album show page. I want to get rid of that.
Here is an image of the problem. I have used CSS to highlight reviews in red. As you can see, there is an empty review at the bottom. When I inspect the review in question, it's raty title is "Not reviewed yet!"
Here is my albums_controller:
class AlbumsController < ApplicationController
before_action :set_album, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, only: [:edit, :new, :update, :destroy]
def index
#albums = Album.all
if params[:search].nil?
#albums = Album.all.order(year: :desc).order(title: :asc).paginate(:page => params[:page], :per_page => 24)
else
#albums = #albums.where("albums.title || albums.year || albums.artist LIKE ?", "%#{params[:search]}%").order(year: :desc).order(title: :asc).paginate(:page => params[:page], :per_page => 24)
end
end
def show
if #album.reviews.blank?
#average_review = 0
else
#average_review = #album.reviews.average(:rating).round(2)
end
#review = #album.reviews.build
end
def new
#album = Album.new
end
def edit
end
def create
#album = current_user.albums.build(album_params)
respond_to do |format|
if #album.save
format.html { redirect_to #album, notice: 'Album was successfully created.' }
format.json { render :show, status: :created, location: #album }
else
format.html { render :new }
format.json { render json: #album.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #album.update(album_params)
format.html { redirect_to #album, notice: 'Album was successfully updated.' }
format.json { render :show, status: :ok, location: #album }
else
format.html { render :edit }
format.json { render json: #album.errors, status: :unprocessable_entity }
end
end
end
def destroy
#album.destroy
respond_to do |format|
format.html { redirect_to albums_url, notice: 'Album was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_album
#album = Album.find(params[:id])
end
def album_params
params.require(:album).permit(:title, :artist, :year, :cover)
end
end
Here is the album show page, which is where the extra review is being displayed:
<div class="row">
<div class="col-xs-10 col-md-6 col-md-push-3 col-xs-push-1 top bottom">
<%= image_tag #album.cover, class: 'show_image' %>
<h2><%= #album.title %></h2>
<h4><%= #album.artist %></h4>
<h5><%= #album.year %></h5>
<p class="white">Average Review<div class="average-review-rating" data-score=<%= #average_review %>></div></p>
<% if user_signed_in? %>
<% if #album.user_id == current_user.id %>
<%= link_to 'Edit', edit_album_path(#album), class: 'grey' %>
| <%= link_to 'Delete', album_path, method: :delete, data: {confirm: "Are you sure?"}, class: 'grey' %>
<% end %>
<% end %>
<br /><br />
<h4>Reviews</h4>
<% if user_signed_in? %>
<p class="grey">Write a review</p>
<%= form_for [#album, #review] do |r| %>
<div class="form-group">
<div id="rating-form">
<label>Rating</label>
</div>
</div>
<div class="form-group">
<%= r.text_area :comment, class: 'form-control', placeholder: "Write a comment" %>
</div>
<div class="form-group">
<%= r.submit "Create", class: 'btn btn-success' %>
</div>
<% end %>
<% end %>
<br />
<% #album.reviews.each do |r| %>
<div class="red">
<div class="review-rating" data-number="<%= r.rating %>">
</div>
<p class="white"><%= r.comment %></p>
<% if user_signed_in? %>
<% if current_user.id == r.user_id %>
<%= link_to 'Edit', edit_album_review_path(#album, r.id), class: 'grey' %> |
<%= link_to 'Delete', album_review_path(#album, r.id), method: :delete, data: {confirm: "Are you sure?"}, class: 'grey' %>
<% end %>
<% end %>
<br /><br />
</div>
<% end %>
</div>
</div>
<script>
$('.review-rating').raty({
readOnly: true,
score: function() {
return $(this).attr('data-number');
},
path: '/assets/'
});
$('#rating-form').raty({
path: '/assets/',
scoreName: 'review[rating]'
});
$('.average-review-rating').raty({
readOnly: true,
path: '/assets/',
score: function() {
return $(this).attr('data-score')
}
});
</script>
Any help would be very appreciated!
The problem here is on the last line of your show method: #review = #album.reviews.build. This line not only creates a new Review instance and assigns it to #review, but it also adds that instance to the array in #album.reviews. So, in your view, when you iterate over #album.reviews, you will see all of the persisted reviews as well as the one new, not persisted review that was built with build.
The easiest way to fix this would be to add this line in your view:
<% #album.reviews.each do |r| %>
<% next unless r.persisted? %>
Another solution would be to associate the new review with the album, but not on the #album instance. In the controller:
#review = Review.new(album: #album)
I think it could be because of last line in show.
#review = #album.reviews.build
It builds an empty review.

Error in rails 5 form on Create

I am new in rails and I'm trying to make a form to associate roles with users, I have two collection_select in the form but when I want to create or update I get this error:
my controller code is :
class UserRolesController < ApplicationController
before_action :set_user_role, only: [:show, :edit, :update, :destroy]
##roles =RolesController.new
##users =UsersController.new
# GET /user_roles
# GET /user_roles.json
def index
#user_roles = UserRole.all
end
# GET /user_roles/1
# GET /user_roles/1.json
def show
end
# GET /user_roles/new
def new
#user_role = UserRole.new
#users =##users.get_all_users
#roles =##roles.get_all_roles
end
# GET /user_roles/1/edit
def edit
#users =##users.get_all_users
#roles =##roles.get_all_roles
#user_roles =UserRole.find(params[:id])
#selected_role=#user_roles.role_id
#selected_user=#user_roles.user_id
end
# POST /user_roles
# POST /user_roles.json
def create
#user_role = UserRole.new(user_role_params)
respond_to do |format|
if #user_role.save
format.html { redirect_to #user_role, notice: 'User role was successfully created.' }
format.json { render :show, status: :created, location: #user_role }
else
format.html { render :new }
format.json { render json: #user_role.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /user_roles/1
# PATCH/PUT /user_roles/1.json
def update
respond_to do |format|
if #user_role.update(user_role_params)
format.html { redirect_to #user_role, notice: 'User role was successfully updated.' }
format.json { render :show, status: :ok, location: #user_role }
else
format.html { render :edit }
format.json { render json: #user_role.errors, status: :unprocessable_entity }
end
end
end
# DELETE /user_roles/1
# DELETE /user_roles/1.json
def destroy
#user_role.destroy
respond_to do |format|
format.html { redirect_to user_roles_url, notice: 'User role was successfully destroyed.' }
format.json { head :no_content }
end
end
def get_user_role_by_userid(user_id)
return UserRole.where(user_id:user_id).first
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user_role
#user_role = UserRole.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_role_params
params.require(:user_role).permit(:role_id,:user_id)
end
end
My form code is :
<%= form_for(user_role) do |f| %>
<% if user_role.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user_role.errors.count, "error") %> prohibited this user_role from being saved:</h2>
<ul>
<% user_role.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user %>
<%= collection_select(:user_id, :user_id,#users, :id, :name,{:selected => #selected_user}) %>
</div>
<div class="field">
<%= f.label :rol %>
<%= collection_select(:role_id, :role_id,#roles, :id, :role {:selected => #selected_role}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
What i am doing wrong? , how i have to set the user_role_params in this case?
I am using ruby 2.3.1 and Rails : 5.0.1
Thanks for your suggestions.
You need to put an f before collection set like this:
<%= form_for(user_role) do |f| %>
<% if user_role.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user_role.errors.count, "error") %> prohibited this user_role from being saved:</h2>
<ul>
<% user_role.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user %>
<%= f.collection_select(:user_id, #users, :id, :name,{:selected => #selected_user}) %>
</div>
<div class="field">
<%= f.label :rol %>
<%= f.collection_select(:role_id, #roles, :id, :role {:selected => #selected_role}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
otherwise the params are being sent like user_id instead of user_role[user_id]

No route matches ... missing required keys: [:id]

I have a sidebar which displays the user's constructions.
I display it this way:
<% current_user.constructions.each do |obra| %>
<li>
<%= link_to construction_path(obra) do %>
<i class="fa fa-home"></i> <%= obra.name %>
<% end %>
<ul class="nav child_menu" style="display: block">
<li>
<%= link_to "Documentos", construction_docs_path(obra) %>
</li>
<li>
<%= link_to "Meus Pagamentos", construction_boletos_path(obra) %>
</li>
</ul>
</li>
<% end %>
It's working with everything, except when I try to create a New Construction, it says:
No route matches {:action=>"show", :controller=>"constructions", :id=>nil}
missing required keys: [:id]
I guess that's because it loses track of the current_user.constructions since my controller makes the
def new
#construction = current_user.constructions.build
end
call...
How can I pass the current constructions' ids, displaying it at the same time that I create a new construction?
EDIT -
constructions_controller.rb
class constructionsController < ApplicationController
before_filter :authenticate_user!
before_action :set_construction, only: [:show, :edit, :update, :destroy]
# GET /constructions
# GET /constructions.json
def index
#constructions = Construction.all
end
# GET /constructions/1
# GET /constructions/1.json
def show
end
# GET /constructions/new
def new
#construction = current_user.constructions.build
end
# GET /constructions/1/edit
def edit
end
# POST /constructions
# POST /constructions.json
def create
#construction = current_user.constructions.build(construction_params)
respond_to do |format|
if #construction.save
format.html { redirect_to #construction, notice: 'construction was successfully created.' }
format.json { render :show, status: :created, location: #construction }
else
format.html { render :new }
format.json { render json: #construction.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /constructions/1
# PATCH/PUT /constructions/1.json
def update
respond_to do |format|
if #construction.update(construction_params)
format.html { redirect_to #construction, notice: 'construction was successfully updated.' }
format.json { render :show, status: :ok, location: #construction }
else
format.html { render :edit }
format.json { render json: #construction.errors, status: :unprocessable_entity }
end
end
end
# DELETE /constructions/1
# DELETE /constructions/1.json
def destroy
#construction.destroy
respond_to do |format|
format.html { redirect_to constructions_url, notice: 'construction was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_construction
#construction = Construction.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def construction_params
params.require(:construction).permit(:name, :locale, :start_date, :description, :image)
end
end
routes.rb
Rails.application.routes.draw do
resources :boletos
resources :documentos
resources :constructions do
get 'construction_documents/index', :path => 'docs', :as => 'docs'
get 'construction_boletos/index', :path => 'boletos', :as => 'boletos'
end
devise_for :users
root 'plainpage#index'
end
constructions/new.html.erb
<h1>New Construction</h1>
<%= render 'form' %>
<%= link_to 'Back', constructions_path %>
constructions/_form.html.erb
<%= form_for #construction, html: { multipart: true } do |f| %>
<% if #construction.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#construction.errors.count, "error") %> prohibited this construction from being saved:</h2>
<ul>
<% #construction.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.file_field :image %>
</div>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :locale %><br>
<%= f.text_field :locale %>
</div>
<div class="field">
<%= f.label :start_date %><br>
<%= f.date_select :start_date %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

Encountered "SyntaxError in AssignmentsController#show" error when trying to use if else statement to check if a record exists in the database

I'm trying to use an if else statement in show.html.erb in the Assignment to check if a record in Bid exists. But I encountered a syntax error "SyntaxError in AssignmentsController#show" that occurs on the first line of the code below:
<%= if Bid.exists?(user_id: current_user.id, assignment_id: #assignment.id) %>
<p>it exists</p>
<%= else %>
<p>it doesn't exists</p>
The following is the entire file Assignment/show.html.erb:
<p id="notice"><%= notice %></p>
<p>
<strong>Assignment:</strong>
<%= #assignment.assignment %>
</p>
<p>
<strong>Education:</strong>
<%= #assignment.education.education %>
</p>
<p>
<strong>Subject:</strong>
<%= #assignment.subject.subject %>
</p>
<p>
<strong>Gender prefer:</strong>
<%= #assignment.gender_prefer %>
</p>
<p>
<strong>Timeslot:</strong>
<%= #assignment.timeslot %>
</p>
<p>
<strong>Duration:</strong>
<%= #assignment.duration %>
</p>
<p>
<strong>Budget:</strong>
<%= #assignment.budget %>
</p>
<p>
<strong>Budget unit:</strong>
<%= #assignment.budget_unit %>
</p>
<p>
<strong>Assignment info:</strong>
<%= #assignment.assignment_info %>
</p>
<p>
<strong>Assignment id:</strong>
<%= #assignment.id %>
</p>
<%= if Bid.exists?(user_id: current_user.id, assignment_id: #assignment.id) %>
<p>it exists</p>
<%= else %>
<p>it doesn't exists</p>
<%= end %>
<%= link_to "Create Bid", bids_path(:status => "Pending", :assignment_id => #assignment.id, :user_id => current_user.id), :method => :post %> |
<%= link_to 'Bid', {controller: "bids", action: "new", id: #assignment.id} %> |
<%= link_to 'Bid', bid_path, method: :post %> |
<%= link_to 'Bid', edit_bid_path %> |
<%= link_to 'Edit', edit_assignment_path(#assignment) %> |
<%= link_to 'Back', assignments_path %>
The following is the entire file assignments_controller.rb:
class AssignmentsController < ApplicationController
before_action :authenticate_user!
before_action :set_assignment, only: [:show, :edit, :update, :destroy]
# GET /assignments
# GET /assignments.json
def index
#assignments = Assignment.all
end
# GET /assignments/1
# GET /assignments/1.json
def show
end
# GET /assignments/new
def new
#assignment = Assignment.new
end
# GET /assignments/1/edit
def edit
end
# POST /assignments
# POST /assignments.json
def create
#assignment = Assignment.new(assignment_params)
respond_to do |format|
if #assignment.save
format.html { redirect_to #assignment, notice: 'Assignment was successfully created.' }
format.json { render :show, status: :created, location: #assignment }
else
format.html { render :new }
format.json { render json: #assignment.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /assignments/1
# PATCH/PUT /assignments/1.json
def update
respond_to do |format|
if #assignment.update(assignment_params)
format.html { redirect_to #assignment, notice: 'Assignment was successfully updated.' }
format.json { render :show, status: :ok, location: #assignment }
else
format.html { render :edit }
format.json { render json: #assignment.errors, status: :unprocessable_entity }
end
end
end
# DELETE /assignments/1
# DELETE /assignments/1.json
def destroy
#assignment.destroy
respond_to do |format|
format.html { redirect_to assignments_url, notice: 'Assignment was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_assignment
#assignment = Assignment.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def assignment_params
params.require(:assignment).permit(:assignment, :education_id, :subject_id, :gender_prefer, :timeslot, :duration, :budget, :budget_unit, :assignment_info)
end
end
I've tried simple if else statements which stills returns an error:
<%= if 1 > 0 %>
<p>it exists</p>
<%= else %>
<p>it doesn't exists</p>
<%= end %>
You must not put the = sign in your erb tags with if, else or end. Try something like this :
<% if 1 > 0 %>
<p>it exists</p>
<% else %>
<p>it doesn't exists</p>
<% end %>
<%= %> will print the result of your line into the generated html. So for all the lines that you don't want to print (like the if , else or for statements, and the end too), use <% %> instead.
If you want more details on erb tags, there is this this SO answer : What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
you are not allowed to add = with if.
Use if like this
<% if 1 > 0 %>
<p>it exists</p>
<% end %>

how to get hanzq/youtube_addy gem working?

So, I have a rails app that allows users to submit youtube links and rank the songs/links using the thumbs up gem.
However, users must physically copy and paste the link into the browser to listen to the song after the link is uploaded. For a better UX I'm going to use this gem to dynamically embed the YouTube video into my app once the users upload the link.
However, I'm not quite sure how this can be done?
I was thinkin' of doing something like this in the index:
<%= YouTubeAddy.extract_video_id('song.url)' %> <%= YouTubeAddy.youtube_embed_url('song.url') %> ?
or would it have to be in the controller? and if so how?
song#new.html.erb:
<%= form_for #song, :html => { :multipart => true } do |f| %>
<% if #song.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#song.errors.count, "error") %> prohibited this song from being saved:</h2>
<ul>
<% #song.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="large-6 columns">
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label 'website url' %>
<%= f.text_area :url %>
</div>
<div class="field">
<%= f.label :tag_list, "Genres (separated by commas)" %><br />
<%= f.text_field :tag_list %>
</div>
<p>
<%= f.file_field :track%>
</p>
<div class="actions">
<%= f.submit value: "Upload" %>
</div>
<% end %>
</div>
song_controller.rb
class SongsController < ApplicationController
before_filter :authenticate_user!, only: [:create ,:edit, :update, :destroy, :vote_for_song]
before_action :set_song, only: [:show, :edit, :update, :destroy, :vote_for_song]
def vote_for
#song = Song.find(params[:id])
current_user.vote_for(#song)
#song.plusminus = #song.votes_for
#song.save
respond_to do |format|
format.js { render 'update_votes' }
end
end
def vote_against
#song = Song.find(params[:id])
current_user.vote_against(#song)
respond_to do |format|
format.js { render 'update_votes' }
end
end
def new_songs
#songs = Song.order "id DESC"
end
# GET /Songs
# GET /Songs.json
def index
if params[:genre]
#songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
else
#songs = Song.order('plusminus').paginate(:page => params[:page], :per_page => 15)
end
end
# GET /Songs/1
# GET /Songs/1.json
def show
#comment = Comment.new(song: #song)
end
# GET /Songs/new
def new
#song = Song.new
end
# GET /Songs/1/edit
def edit
end
# POST /Songs
# POST /Songs.json
def create
#song = Song.new(song_params)
respond_to do |format|
if #song.save
format.html { redirect_to #song, notice: 'Song was successfully created.' }
format.json { render action: 'show', status: :created, location: #song }
else
format.html { render action: 'new' }
format.json { render json: #song.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /Songs/1
# PATCH/PUT /Songs/1.json
def update
respond_to do |format|
if #song.update(song_params)
format.html { redirect_to #song, notice: 'Song was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #song.errors, status: :unprocessable_entity }
end
end
end
# Song /Songs/1
# Song /Songs/1.json
def destroy
#song.destroy
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end
private
def set_song
#song = Song.find(params[:id])
end
def song_params
params.require(:song).permit(:title, :artist, :url, :track, :user_id, :tag_list)
end
end
index.html.erb
<h6>Top ranked songs</h6>
<hr>
<ol><% #songs.each do |song| %>
<span class="title">
<li><%=link_to image_tag('thumbs.png', size: '16x50'), vote_for_song_path(song), :remote => true, :method => :put %> <%= link_to song.title, song %><span class="subtext"> (<%= song.url %>)<br></li></span>
<%#=link_to '&#9660'.html_safe, vote_against_song_path(song), :remote => true, :method => :put %>
<span class="subtext"><span class="votes_<%= song.id %>"><%= pluralize(song.votes.count, 'like') %>,</span>
posted <%= time_ago_in_words(song.created_at) + " ago" %>
<small><span class="comments"></small> | <%= pluralize(song.comments.size, 'comment') %></span></small><br /></span>
<%#= link_to 'Show', song, class: "button small secondary" %>
<%= link_to('Edit', edit_song_path(song), class: "button small secondary") if can? :update, song %>
<%= link_to('Destroy', song, method: :delete, data: {confirm: 'Are you sure?'}, class: "button small secondary") if can? :destroy, song %>
<% end %>
</ol>
<div class="pagination-centered">
<ul class="pagination">
<%#= will_paginate #songs %>
<!-- or custom pagination -->
<% if #songs.previous_page %>
<%= link_to "Back", params.merge(page: #songs.previous_page) %>
<% end %>
<% if #songs.next_page %>
<%= link_to "More", params.merge(page: #songs.next_page) %>
<% end %>
</ul></div>
YouTubeAddy.youtube_embed_url('song.url') generates a string of iframe tag, so it should be used in your view exactly where you want an embedded video to be placed. But note that you should return an html safe string. So in your view you have:
<%=raw YouTubeAddy.youtube_embed_url('song.url') %>
More about unescaping html.

Resources