Add reminder feature
This commit is contained in:
3
app/assets/stylesheets/reminders.scss
Normal file
3
app/assets/stylesheets/reminders.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Reminders controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: https://sass-lang.com/
|
65
app/assets/stylesheets/scaffolds.scss
Normal file
65
app/assets/stylesheets/scaffolds.scss
Normal file
@ -0,0 +1,65 @@
|
||||
body {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
margin: 33px; }
|
||||
|
||||
body, p, ol, ul, td {
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px; }
|
||||
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px; }
|
||||
|
||||
a {
|
||||
color: #000; }
|
||||
|
||||
a:visited {
|
||||
color: #666; }
|
||||
|
||||
a:hover {
|
||||
color: #fff;
|
||||
background-color: #000; }
|
||||
|
||||
th {
|
||||
padding-bottom: 5px; }
|
||||
|
||||
td {
|
||||
padding: 0 5px 7px; }
|
||||
|
||||
div.field,
|
||||
div.actions {
|
||||
margin-bottom: 10px; }
|
||||
|
||||
#notice {
|
||||
color: green; }
|
||||
|
||||
.field_with_errors {
|
||||
padding: 2px;
|
||||
background-color: red;
|
||||
display: table; }
|
||||
|
||||
#error_explanation {
|
||||
width: 450px;
|
||||
border: 2px solid red;
|
||||
padding: 7px 7px 0;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0; }
|
||||
|
||||
#error_explanation h2 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 5px 5px 5px 15px;
|
||||
font-size: 12px;
|
||||
margin: -7px -7px 0;
|
||||
background-color: #c00;
|
||||
color: #fff; }
|
||||
|
||||
#error_explanation ul li {
|
||||
font-size: 12px;
|
||||
list-style: square; }
|
||||
|
||||
label {
|
||||
display: block; }
|
@ -1,2 +1,3 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :authenticate_user!
|
||||
end
|
||||
|
51
app/controllers/reminders_controller.rb
Normal file
51
app/controllers/reminders_controller.rb
Normal file
@ -0,0 +1,51 @@
|
||||
class RemindersController < ApplicationController
|
||||
before_action :set_reminder, only: %i[show edit update destroy]
|
||||
|
||||
def index
|
||||
@reminders = Reminder.all
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def new
|
||||
@reminder = Reminder.new
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
@reminder = Reminder.new(reminder_params)
|
||||
@reminder.user_id = current_user.id
|
||||
|
||||
if @reminder.save
|
||||
redirect_to @reminder, notice: 'Reminder was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @reminder.update(reminder_params)
|
||||
redirect_to @reminder, notice: 'Reminder was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@reminder.destroy
|
||||
redirect_to reminders_url, notice: 'Reminder was successfully destroyed.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_reminder
|
||||
@reminder = Reminder.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def reminder_params
|
||||
params.require(:reminder).permit(:title, :body, :date, :user_id)
|
||||
end
|
||||
end
|
2
app/helpers/reminders_helper.rb
Normal file
2
app/helpers/reminders_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module RemindersHelper
|
||||
end
|
7
app/models/reminder.rb
Normal file
7
app/models/reminder.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class Reminder < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
validates :title, presence: true
|
||||
validates :body, presence: true
|
||||
validates :date, presence: true
|
||||
end
|
@ -11,5 +11,10 @@
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
|
||||
<hr>
|
||||
<% if user_signed_in? %>
|
||||
<p><%= link_to('Logout', destroy_user_session_path) %></p>
|
||||
<% end %>
|
||||
</body>
|
||||
</html>
|
||||
|
32
app/views/reminders/_form.html.erb
Normal file
32
app/views/reminders/_form.html.erb
Normal file
@ -0,0 +1,32 @@
|
||||
<%= form_with(model: reminder, local: true) do |form| %>
|
||||
<% if reminder.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(reminder.errors.count, "error") %> prohibited this reminder from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% reminder.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :title %>
|
||||
<%= form.text_field :title %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :body %>
|
||||
<%= form.text_area :body %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :date %>
|
||||
<%= form.datetime_select :date %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
6
app/views/reminders/edit.html.erb
Normal file
6
app/views/reminders/edit.html.erb
Normal file
@ -0,0 +1,6 @@
|
||||
<h1>Editing Reminder</h1>
|
||||
|
||||
<%= render 'form', reminder: @reminder %>
|
||||
|
||||
<%= link_to 'Show', @reminder %> |
|
||||
<%= link_to 'Back', reminders_path %>
|
31
app/views/reminders/index.html.erb
Normal file
31
app/views/reminders/index.html.erb
Normal file
@ -0,0 +1,31 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>Reminders</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Body</th>
|
||||
<th>Date</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @reminders.each do |reminder| %>
|
||||
<tr>
|
||||
<td><%= reminder.title %></td>
|
||||
<td><%= reminder.body %></td>
|
||||
<td><%= reminder.date %></td>
|
||||
<td><%= link_to 'Show', reminder %></td>
|
||||
<td><%= link_to 'Edit', edit_reminder_path(reminder) %></td>
|
||||
<td><%= link_to 'Destroy', reminder, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Reminder', new_reminder_path %>
|
5
app/views/reminders/new.html.erb
Normal file
5
app/views/reminders/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<h1>New Reminder</h1>
|
||||
|
||||
<%= render 'form', reminder: @reminder %>
|
||||
|
||||
<%= link_to 'Back', reminders_path %>
|
19
app/views/reminders/show.html.erb
Normal file
19
app/views/reminders/show.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>Title:</strong>
|
||||
<%= @reminder.title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Body:</strong>
|
||||
<%= @reminder.body %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Date:</strong>
|
||||
<%= @reminder.date %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_reminder_path(@reminder) %> |
|
||||
<%= link_to 'Back', reminders_path %>
|
Reference in New Issue
Block a user