Class: RelationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RelationsController
- Defined in:
- app/controllers/relations_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#edit ⇒ Object
TODO: test.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from Zena::App
Instance Method Details
#create ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/relations_controller.rb', line 62 def create @relation = Relation.new(params[:relation]) respond_to do |format| if @relation.save flash.now[:notice] = _('Relation was successfully created.') format.html { redirect_to relation_url(@relation) } format.js format.xml { render :xml => @relation, :status => :created, :location => relation_url(@relation) } else format.html { render :action => "new" } format.js format.xml { render :xml => @relation.errors } end end end |
#destroy ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/relations_controller.rb', line 96 def destroy @relation.destroy respond_to do |format| format.html { redirect_to relations_url } format.xml { head :ok } format.js end end |
#edit ⇒ Object
TODO: test
55 56 57 58 59 60 |
# File 'app/controllers/relations_controller.rb', line 55 def edit respond_to do |format| format.html format.js { render :partial => 'relations/form', :layout => false } end end |
#index ⇒ Object
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 |
# File 'app/controllers/relations_controller.rb', line 7 def index secure(Relation) do @relations = Relation.paginate(:all, :order => 'source_kpath', :per_page => 20, :page => params[:page]) end @classes = {} @relations.each do |rel| (@classes[rel.source_kpath] ||= []) << ['src', rel] (@classes[rel.target_kpath] ||= []) << ['trg', rel] end @classes.each do |k, list| list.sort! do |a,b| a_s = a[0] == 'src' ? a[1].target_role : a[1].source_role b_s = b[0] == 'src' ? b[1].target_role : b[1].source_role a_s <=> b_s end end @relation = Relation.new respond_to do |format| format.html # index.erb format.xml { render :xml => @relations } end rescue ActiveRecord::RecordNotFound => err Node.logger.warn "NotFound: #{err.}" Node.logger.warn err.backtrace.join("\n") raise err end |
#new ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/controllers/relations_controller.rb', line 45 def new @relation = Relation.new respond_to do |format| format.html # new.erb format.xml { render :xml => @relation } end end |
#show ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/controllers/relations_controller.rb', line 37 def show respond_to do |format| format.html # show.erb format.xml { render :xml => @relation } format.js end end |
#update ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/relations_controller.rb', line 79 def update @relation = Relation.find(params[:id]) respond_to do |format| if @relation.update_attributes(params[:relation]) flash.now[:notice] = _('Relation was successfully updated.') format.html { redirect_to relation_url(@relation) } format.js format.xml { head :ok } else format.html { render :action => "edit" } format.js format.xml { render :xml => @relation.errors } end end end |