1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class NewsController < ApplicationController roar :subdomain => "admin" do order "posted_at DESC" filters do search :text, [:title, :intro, :body] select_field :status, :choices => News.status_options, :prompt=>"Status:" recent_dates :posted_at end table do edit :title date :posted_at, :format=>:short inline_select :status, :choices => News.status_options column :author delete end form do text_field :title text_area :intro text_area :body select_field :news_category_id, :choices => NewsCategory.to_select, :prompt=>true select_field :status, :choices => News.status_options, :prompt=>true end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
class EventsController < ApplicationController roar :subdomain=>"admin" do order "date DESC" per_page 10 filters do search :text, [:name,:location,:description] recent_dates :date end table do edit :name date :date column :location delete end form do text_field :name text_field :location datetime_select :date text_area :description end end end |
This shot illustrates nested resources, with inline editing—Divisions are nested within Leagues.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
class LeaguesController < ApplicationController roar :subdomain=>"admin" do order "year DESC" include "divisions" table do edit :name column :year column :season has_many :divisions, :inline=>true delete end form do text_field :name select_field :season, :choices => League.season_options, :prompt => true end end end class DivisionsController < ApplicationController roar :subdomain=>"admin", :parent=>:league do table do edit :name has_many :games has_many :teams delete end form do text_field :name end end end |
This shot illustrates the scoped select field in action. Divisions are scoped to a League, and Teams are scoped to the Division.
This shot also illustrates the custom actions in place (:save_and_add_another).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
class GamesController < ApplicationController roar :subdomain => "admin" do order "scheduled_at DESC" include [:division, :league, :team1, :team2] filters do select_field "league_id", :choices=>League.to_select, :prompt=>"League:" scoped_select_field "division_id", :to=>:league_id, :prompt=> "Division:" end table do edit(:scheduled_at) { |date| date.to_s(:short) } column(:division) { |div| "#{div.league.name}, #{div.name}" } column "team1.name" column "team2.name" column "score1" column "score2" column :played delete end form do select_field :league_id, :choices => League.to_select, :prompt => "League: " scoped_select_field :division_id, :to => :league_id, :prompt => "Division: " do |league_id| League.find(league_id).divisions.map { |div| [div.name, div.id] } end scoped_select_field :team1_id, :source => :team, :to => :division_id, :prompt => "Team 1:" do |div_id| Division.find(div_id).teams.map { |team| [team.name, team.id] } end scoped_select_field :team2_id, :source => :team, :to => :division_id, :prompt => "Team 2:" do |div_id| Division.find(div_id).teams.map { |team| [team.name, team.id] } end datetime_select :scheduled_at text_field :duration actions [:save, :save_and_add_another, :delete] end end end |
Roar is a plugin for Ruby on Rails that provides an automated admin interface for resources. It provides non intrusive and degradable ajax based CRUD, relationship editing, advanced widgets and more.
Copyright © 2006 - 2007 Nanoware.