Skip to content

Commit

Permalink
Още по обявите
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 1, 2010
1 parent ac5ab56 commit 994885a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 99 deletions.
40 changes: 20 additions & 20 deletions app/controllers/admin/announcements_controller.rb
@@ -1,83 +1,83 @@
class Admin::AnnouncementsController < Admin::BaseController
layout "admin", :except => [:help]
layout "admin"
# GET /admin/announcements
# GET /admin/announcements.xml
def index
@admin_announcements = Admin::Announcement.all
@announcements = Announcement.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @admin_announcements }
end
end

# GET /admin/announcements/1
# GET /admin/announcements/1.xml
def show
@admin_announcement = Admin::Announcement.find(params[:id])
@announcement = Announcement.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @admin_announcement }
format.xml { render :xml => @announcement }
end
end

# GET /admin/announcements/new
# GET /admin/announcements/new.xml
def new
@admin_announcement = Admin::Announcement.new
@announcement = Announcement.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @admin_announcement }
format.xml { render :xml => @announcement }
end
end

# GET /admin/announcements/1/edit
def edit
@admin_announcement = Admin::Announcement.find(params[:id])
@announcement = Announcement.find(params[:id])

end

# POST /admin/announcements
# POST /admin/announcements.xml
def create
@admin_announcement = Admin::Announcement.new(params[:admin_announcement])
@announcement = Announcement.new(params[:announcement])

respond_to do |format|
if @admin_announcement.save
format.html { redirect_to(@admin_announcement, :notice => 'Announcement was successfully created.') }
format.xml { render :xml => @admin_announcement, :status => :created, :location => @admin_announcement }
if @announcement.save
format.html { redirect_to(admin_announcement_path(@announcement), :notice => 'Announcement was successfully created.') }
format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
else
format.html { render :action => "new" }
format.xml { render :xml => @admin_announcement.errors, :status => :unprocessable_entity }
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end

# PUT /admin/announcements/1
# PUT /admin/announcements/1.xml
def update
@admin_announcement = Admin::Announcement.find(params[:id])
@announcement = Announcement.find(params[:id])

respond_to do |format|
if @admin_announcement.update_attributes(params[:admin_announcement])
format.html { redirect_to(@admin_announcement, :notice => 'Announcement was successfully updated.') }
if @announcement.update_attributes(params[:announcement])
format.html { redirect_to(edit_admin_announcement_path(@announcement), :notice => 'Announcement was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @admin_announcement.errors, :status => :unprocessable_entity }
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /admin/announcements/1
# DELETE /admin/announcements/1.xml
def destroy
@admin_announcement = Admin::Announcement.find(params[:id])
@admin_announcement.destroy
#@announcement = Announcement.find(params[:id])
@announcement.destroy

respond_to do |format|
format.html { redirect_to(admin_announcements_url) }
format.html { redirect_to [@announcements] }
format.xml { head :ok }
end
end
Expand Down
@@ -1,4 +1,4 @@
class Admin::Announcement
class Announcement
include Mongoid::Document
field :title, :type => String
field :description, :type => String
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/announcements/_form.html.erb
@@ -1,10 +1,10 @@
<%= semantic_form_for(:admin, @admin_announcement) do |f| %>
<% if @admin_announcement.errors.any? %>
<%= semantic_form_for([:admin, @announcement]) do |f| %>
<% if @announcement.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@admin_announcement.errors.count, "error") %> prohibited this admin_announcement from being saved:</h2>
<h2><%= pluralize(@announcement.errors.count, "error") %> prohibited this admin_announcement from being saved:</h2>

<ul>
<% @admin_announcement.errors.full_messages.each do |msg| %>
<% @announcement.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/announcements/edit.html.erb
Expand Up @@ -2,5 +2,6 @@

<%= render 'form' %>
<%= link_to 'Show', @admin_announcement %> |
<%= link_to 'Show', admin_announcement_path(@announcement) %> |
<%= link_to 'Back', admin_announcements_path %>
14 changes: 7 additions & 7 deletions app/views/admin/announcements/index.html.erb
Expand Up @@ -9,14 +9,14 @@

</tr>

<% @admin_announcements.each do |admin_announcement| %>
<% @announcements.each do |announcement| %>
<tr>
<td><%= link_to admin_announcement.title, admin_announcement %></td>
<td><%= admin_announcement.description %></td></p>
<td><%= admin_announcement.author %></td>
<td><%= admin_announcement.img_url %></td>
<td><%= link_to 'Edit', edit_admin_announcement_path(admin_announcement) %></td>
<td><%= link_to 'Destroy', admin_announcement, :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= link_to announcement.title, [:admin, announcement] %></td>
<td><%= announcement.description %></td>
<td><%= announcement.author %></td>
<td><%= announcement.img_url %></td>
<td><%= link_to 'Edit', edit_admin_announcement_path(announcement) %></td>
<td><%= link_to 'Destroy', [:admin, announcement], :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/announcements/show.html.erb
Expand Up @@ -2,24 +2,24 @@

<p>
<b>Заглавие:</b>
<%= @admin_announcement.title %>
<%= @announcement.title %>
</p>

<p>
<b>Описание:</b>
<%= @admin_announcement.description %>
<%= @announcement.description %>
</p>

<p>
<b>Автор:</b>
<%= @admin_announcement.author %>
<%= @announcement.author %>
</p>

<p>
<b>Снимка:</b>
<%= @admin_announcement.img_url %>
<%= @announcement.img_url %>
</p>


<%= link_to 'Edit', edit_admin_announcement_path(@admin_announcement) %> |
<%= link_to 'Edit', edit_admin_announcement_path(@announcement) %> |
<%= link_to 'Back', admin_announcements_path %>
123 changes: 62 additions & 61 deletions config/routes.rb
@@ -1,8 +1,6 @@
Kvartala::Application.routes.draw do


namespace :admin do resources :announcements end

devise_for :users
resources :users, :only => :show
root :to => "home#index"
Expand All @@ -11,69 +9,72 @@
end

namespace :admin do
resources :announcements
resources :towns do
resources :districts do
resources :quarters do
end
end
end
end
end
# resources :districts, :shallow => true do

# The priority is based upon order of creation:
# first created -> highest priority.

# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end

# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'


# resources :districts, :shallow => true do

# The priority is based upon order of creation:
# first created -> highest priority.

# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end

# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end
1 change: 1 addition & 0 deletions db/seeds.rb
Expand Up @@ -10,3 +10,4 @@
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => 'boss@boss.com', :password => '112233', :password_confirmation => '112233'
puts 'New user created: ' << user.name

22 changes: 22 additions & 0 deletions db/seeds_districts.erb
@@ -0,0 +1,22 @@
<%#
# To change this template, choose Tools | Templates
# and open the template in the editor.
%>
<%= "seeds_districts" %>
%w(Средец,Красно село,Възраждане,Оборище,Сердика,Подуяне,Слатина,Изгрев,Лозенец,Триадица
11.Красна поляна12.Илинден
13.Надежда
14.Искър
15.Младост
16.Студентски град
17.Витоша
18.Овча купел
19.Люлин
20.Връбница
21.Нови Искър
22.Кремиковци
23.Панчарево
24.Банкя).each {|name| City.create(:name => name)}


0 comments on commit 994885a

Please sign in to comment.