-
-
Save kwerle/1555587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
def current_search | |
Search.find(session[:search_id]) | |
end | |
def current_search? | |
session[:search_id].present? | |
end | |
def source? | |
params[:source_id].present? | |
end | |
def source | |
Source.find(params[:source_id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MixesController < ApplicationController | |
respond_to :html, :json | |
def index | |
@mixes = mixes.published.page(params[:page]).per(50) | |
respond_with @mixes | |
end | |
private | |
def mixes | |
if source? | |
source.mixes | |
elsif current_search? | |
current_search.mixes | |
else | |
Mix | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Search < ActiveRecord::Base | |
def mixes | |
mixes = Mix.published | |
mixes = mixes.genre(genres) if genres.present? | |
mixes.limit(50) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchesController < ApplicationController | |
respond_to :html, :json | |
def show | |
@search = Search.find(params[:id]) | |
respond_with @search | |
end | |
def update | |
@search = Search.find(params[:id]) | |
@search.update_attributes(params[:search]) | |
respond_with @search | |
end | |
def create | |
@search = Search.create(params[:search]) | |
session[:search_id] = @search.id | |
respond_with @search | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Source < ActiveRecord::Base | |
has_many :mixes, :dependent => :destroy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment