improved pool interface
This commit is contained in:
@@ -16,6 +16,7 @@ class PoolsController < ApplicationController
|
||||
def index
|
||||
@search = Pool.search(params[:search])
|
||||
@pools = @search.paginate(:page => params[:page])
|
||||
respond_with(@pools)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
class PoolsPostsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only
|
||||
|
||||
def create
|
||||
@pool = Pool.find(params[:pool_id])
|
||||
@post = Post.find(params[:id])
|
||||
@pool = Pool.find_by_name(params[:pool_name]) || Pool.find(params[:pool_id])
|
||||
@post = Post.find(params[:post_id])
|
||||
@pool.add_post!(@post)
|
||||
append_pool_to_session(@pool)
|
||||
respond_with(@pool, :location => pool_path(@pool))
|
||||
end
|
||||
|
||||
def destroy
|
||||
@pool = Pool.find(params[:pool_id])
|
||||
@post = Post.find(params[:id])
|
||||
@post = Post.find(params[:post_id])
|
||||
@pool.remove_post!(@post)
|
||||
respond_with(@pool, :location => pool_path(@pool))
|
||||
end
|
||||
|
||||
private
|
||||
def append_pool_to_session(pool)
|
||||
recent_pool_ids = session[:recent_pool_ids].to_s.scan(/\d+/)
|
||||
recent_pool_ids << pool.id.to_s
|
||||
recent_pool_ids = recent_pool_ids.slice(1, 5) if recent_pool_ids.size > 5
|
||||
session[:recent_pool_ids] = recent_pool_ids.uniq.join(",")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module PoolsHelper
|
||||
def recent_pool_list
|
||||
pool_ids = session[:recent_pool_ids].to_s.split(/,/)
|
||||
pool_ids.map {|x| content_tag("option", x, :value => x)}.join("\n").html_safe
|
||||
def recent_updated_pools(&block)
|
||||
pool_ids = session[:recent_pool_ids].to_s.scan(/\d+/)
|
||||
Pool.where(["id IN (?)", pool_ids]).each(&block) if pool_ids.any?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<%= simple_form_for(pool) do |f| %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :description %>
|
||||
<%= f.input :is_active %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
<%= form_for(post_pools_path(@post)) do %>
|
||||
<p>Select a pool:</p>
|
||||
<%= recent_pool_list %>
|
||||
<% end %>
|
||||
<div id="c-pools-posts">
|
||||
<div id="a-new">
|
||||
<%= form_tag(pool_post_path) do %>
|
||||
<%= hidden_field_tag "post_id", @post.id %>
|
||||
<%= text_field_tag "pool_name", "", :size => 20 %>
|
||||
<%= submit_tag "Select" %>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<h1>Recent Pools</h1>
|
||||
<ul id="recent-pools">
|
||||
<% recent_updated_pools.each do |pool| %>
|
||||
<li><%= pool.name %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user