Commit fe7d2f8
Changed files (7)
app
controllers
config
app/controllers/events_controller.rb
@@ -1,64 +1,23 @@
class EventsController < ApplicationController
- before_action :set_event, only: [:show, :edit, :update, :destroy]
-
- # GET /events
- # GET /events.json
def index
@events = Event.all
end
- # GET /events/1
- # GET /events/1.json
- def show
- end
-
- # GET /events/new
def new
@event = Event.new
end
- # GET /events/1/edit
- def edit
- end
-
- # POST /events
- # POST /events.json
def create
Publisher.publish("events", event_params)
redirect_to events_path, notice: 'Event was successfully created.'
end
- # PATCH/PUT /events/1
- # PATCH/PUT /events/1.json
- def update
- respond_to do |format|
- if @event.update(event_params)
- format.html { redirect_to @event, notice: 'Event was successfully updated.' }
- format.json { render :show, status: :ok, location: @event }
- else
- format.html { render :edit }
- format.json { render json: @event.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /events/1
- # DELETE /events/1.json
def destroy
- @event.destroy
- respond_to do |format|
- format.html { redirect_to events_url, notice: 'Event was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
-
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_event
@event = Event.find(params[:id])
+ @event.destroy
+ redirect_to events_url, notice: 'Event was successfully destroyed.'
end
- # Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event).permit(:name, :data)
end
app/views/events/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing Event</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @event %> |
-<%= link_to 'Back', events_path %>
app/views/events/index.html.erb
@@ -7,7 +7,8 @@
<tr>
<th>Name</th>
<th>Data</th>
- <th colspan="3"></th>
+ <th>Created At</th>
+ <th></th>
</tr>
</thead>
@@ -16,8 +17,7 @@
<tr>
<td><%= event.name %></td>
<td><%= event.data %></td>
- <td><%= link_to 'Show', event %></td>
- <td><%= link_to 'Edit', edit_event_path(event) %></td>
+ <td><%= event.created_at %></td>
<td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
app/views/events/index.json.jbuilder
@@ -1,4 +0,0 @@
-json.array!(@events) do |event|
- json.extract! event, :id, :name, :data
- json.url event_url(event, format: :json)
-end
app/views/events/show.html.erb
@@ -1,14 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <strong>Name:</strong>
- <%= @event.name %>
-</p>
-
-<p>
- <strong>Data:</strong>
- <%= @event.data %>
-</p>
-
-<%= link_to 'Edit', edit_event_path(@event) %> |
-<%= link_to 'Back', events_path %>
app/views/events/show.json.jbuilder
@@ -1,1 +0,0 @@
-json.extract! @event, :id, :name, :data, :created_at, :updated_at
config/routes.rb
@@ -1,4 +1,4 @@
Rails.application.routes.draw do
- resources :events
+ resources :events, only: [:index, :new, :create, :destroy]
root 'events#index'
end