⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sidebar_controller.rb

📁 用ruby on rails写的一个博客程序,还不错..ruby on rails的确是个好框架
💻 RB
字号:
class Admin::SidebarController < Admin::BaseController  def index    @available = available    # Reset the staged position based on the active position.    Sidebar.delete_all(['blog_id = ? and active_position is null',                         this_blog.id])    @active = this_blog.sidebars    flash[:sidebars] = @active.map {|sb| sb.id }  end  def set_active    # Get all available plugins    klass_for = available.inject({}) do |hash, klass|      hash.merge({ klass.short_name => klass })    end    # Get all already active plugins    activemap = flash[:sidebars].inject({}) do |h, sb_id|      sb = Sidebar.find(sb_id.to_i)      sb ? h.merge(sb.html_id => sb_id) : h    end    # Figure out which plugins are referenced by the params[:active] array and    # lay them out in a easy accessible sequential array    flash[:sidebars] = params[:active].inject([]) do |array, name|      if klass_for.has_key?(name)        @new_item = klass_for[name].create!(:blog => this_blog)        @target = name        array << @new_item.id      elsif activemap.has_key?(name)        array << activemap[name]      else        array      end    end  end  def remove    flash[:sidebars] = flash[:sidebars].reject do |sb_id|      sb_id == params[:id].to_i    end    @element_to_remove = params[:element]  end  def publish    Sidebar.transaction do      position = 0      params[:configure] ||= { }      this_blog.sidebars.update_all('active_position = null')      flash[:sidebars].each do |id|        sidebar = Sidebar.find(id)        sb_attribs = params[:configure][id.to_s] || {}        # If it's a checkbox and unchecked, convert the 0 to false        # This is ugly.  Anyone have an improvement?        sidebar.fields.each do |field|          sb_attribs[field.key] = field.canonicalize(sb_attribs[field.key])        end        sidebar.update_attributes(:config => sb_attribs,                                  :active_position => position)        position += 1      end      Sidebar.delete_all(['blog_id = ? and active_position is null',                          this_blog.id])    end    index  end  protected  def show_available    render :partial => 'availables', :object => available  end  def available    ::Sidebar.available_sidebars  end  helper_method :availableend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -