Skip to content
Extraits de code Groupes Projets
Valider e29ff8c0 rédigé par Sybil's avatar Sybil
Parcourir les fichiers

The refactoring continues ! Filters upgraded, tagcloud upgraded.

parent 6055516e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -21,11 +21,8 @@ class ApplicationController < ActionController::Base
@tags = Hash.new
tags.each do |tag|
if @tags.key?(tag.tag)
@tags[tag.tag] ||= 0.0
@tags[tag.tag] += 1.0
else
@tags[tag.tag] = 1.0
end
end
max_weight = @tags.values.max
@tags.each do |tag, occ|
......@@ -42,11 +39,8 @@ class ApplicationController < ActionController::Base
@users = Hash.new
users.each do |user|
if @users.key?(user.sender_irc)
@users[user.sender_irc] ||= 0.0
@users[user.sender_irc] += 1.0
else
@users[user.sender_irc] = 1.0
end
end
max_weight = @users.values.max
......
class MusicsController < ApplicationController
def add_filters(filters)
@musics = @musics.with_tag(filters[:tag_id]) if filters.has_key?(:tag_id)
@musics = @musics.with_channel('#'+filters[:channel_id]) if filters.has_key?(:channel_id)
@musics = @musics.with_user(filters[:user_id]) if filters.has_key?(:user_id)
def filters( *filters )
filters.each do | filter |
if param = params[filter] || params["#{filter}_id"]
@musics = @musics.send( "with_#{filter}", param )
end
end
end
def index
@musics = Music.page params[:page]
add_filters(params)
filters :tag, :channel, :user
respond_to do |format|
format.html
......
......@@ -10,7 +10,7 @@ class Music < ActiveRecord::Base
end
def self.with_channel(channel)
self.joins(:channel).where("channel = ?", channel)
self.joins(:channel).where("channel = ?", "##{channel}")
end
def self.with_user(user)
......
......@@ -9,15 +9,15 @@
end %>">
<span class="music_id"><%= music.id %></span>
<span class="music_chan">
<%= link_to music.channel.chan, '/musics/channels/'+music.channel.chan.sub('#','') %>
<%= link_to music.channel.chan, "/channels/#{music.channel.chan.sub('#','')}/musics" %>
</span>
<span class="music_title">
<%= music.title %>
</span>
<span class="music_tags">
<%= raw(music.tags.map{|t| link_to t.tag, '/musics/tags/'+t.tag}.join(" ")) %>
<%= raw(music.tags.map{|t| link_to t.tag, "/tags/#{t.tag}/musics"}.join(" ")) %>
</span>
<span class="music_sender">
<%= link_to music.channel.sender_irc, '/musics/users/'+music.channel.sender_irc %>
<%= link_to music.channel.sender_irc, "/users/#{music.channel.sender_irc}/musics" %>
</span>
</li>
......@@ -65,10 +65,5 @@ Rails.application.routes.draw do
root to: 'musics#index'
#get '/musics/tags/:tag', to: "tags#show"
#get '/users/:user_id/musics', to: "musics#index"
#get '/musics/channels/:channel', to: "channels#show_channel"
#Experiment
#get '/filters/:channel/:user/:tag', to: "musics#filters"
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter