Permalink
Browse files

add event CRUD

  • Loading branch information...
1 parent 2f40713 commit a87fbfa7e2b7f1047360b838118014377c8958c9 @miau715 committed Oct 19, 2011
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the events controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -32,7 +32,7 @@ def update
flash[:notice] = "成功更新"
redirect_to cat_url(@cat)
else
- render :action => :edit
+ redirect_to edit_cat_url
end
end
@@ -0,0 +1,44 @@
+class EventsController < ApplicationController
+ before_filter :find_event, only: [ :show, :edit, :update, :destroy]
+
+ def index
+ @events = Event.all
+ end
+
+ def new
+ @event = Event.new
+ end
+
+ def create
+ @event = Event.new(params[:event])
+ @event.save
+
+ redirect_to events_url
+ end
+
+ def show
+ @page_title = @event.name
+ end
+
+ def edit
+
+ end
+
+ def update
+ if @event.update_attributes(params[:event])
+ redirect_to event_url(@event)
+ else
+ redirect_to edit_event_url
+ end
+ end
+
+ def destroy
+ @event.destroy
+ redirect_to events_url
+ end
+
+ protected
+ def find_event
+ @event = Event.find(params[:id])
+ end
+end
@@ -0,0 +1,2 @@
+module EventsHelper
+end
View
@@ -0,0 +1,2 @@
+class Event < ActiveRecord::Base
+end
@@ -0,0 +1,6 @@
+ <%= f.label :name, "活動名稱:" %>
+ <%= f.text_field :name %>
+ <br />
+ <%= f.label :description, "活動說明:" %>
+ <%= f.text_area :description %>
+ <br />
@@ -0,0 +1,7 @@
+<h1>編輯活動資料</h1>
+<%= form_for @event, url: event_path(@event), method: :put do |f| %>
+<p>
+ <%= render partial: 'form', locals: { f: f } %>
+</p>
+ <%= f.submit "我變" %><%= link_to '不想變了', events_path %>
+<% end %>
@@ -0,0 +1,15 @@
+<h1>活動列表</h1>
+<ul>
+<% @events.each do |list| %>
+ <li>
+ <%= list.name %>
+ <%= link_to '顯示', event_path(list) %>
+ <%= link_to '編輯', edit_event_path(list) %>
+ <%= button_to '刪除', event_path(list), method: :delete %>
+ </li>
+<% end %>
+</ul>
+<p>
+ <%= link_to '建立新活動', new_event_path %>
+</p>
+
@@ -0,0 +1,5 @@
+<h1>加入新活動</h1>
+<%= form_for @event, url: events_path do |f| %>
+ <%= render partial: 'form', locals: { f: f } %>
+ <%= f.submit "Create" %>
+<% end %>
@@ -0,0 +1,5 @@
+<h1>活動資料</h1>
+<p>活動名稱:<%= @event.name %></p>
+<p>活動說明:<%= @event.description%></p>
+
+<p><%= link_to '回活動列表', events_path %></p>
View
@@ -20,6 +20,9 @@
end
end
+ resources :events do
+ end
+
# Sample resource route with options:
# resources :products do
# member do
@@ -56,7 +59,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
- root :to => 'cats#index'
+ #root :to => 'cats#index'
# See how all your routes lay out with "rake routes"
@@ -0,0 +1,10 @@
+class CreateEvents < ActiveRecord::Migration
+ def change
+ create_table :events do |t|
+ t.string :name
+ t.text :description
+
+ t.timestamps
+ end
+ end
+end
View
@@ -11,14 +11,21 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111018164629) do
+ActiveRecord::Schema.define(:version => 20111019020248) do
create_table "cats", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
+ create_table "events", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
View
@@ -0,0 +1,5 @@
+namespace :dev do
+ desc "Rebuild system"
+ task :build => ["tmp:clear", "log:clear", "db:drop", "db:create", "db:migrate"]
+ task :rebuild => [ "dev:build", "db:seed" ]
+end
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ descrption: MyText
+
+two:
+ name: MyString
+ descrption: MyText
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class EventsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class EventTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class EventsHelperTest < ActionView::TestCase
+end

0 comments on commit a87fbfa

Please sign in to comment.