-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new buttons such as: - Edit the article - Delete the article - Create an article - View the article Added a new design of the main page Added the design of the page for Adding a new article Added work with the database. all Articles are now edited in the user Database at any operation with them
- Loading branch information
Showing
8 changed files
with
233 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
class ArticlesController < ApplicationController | ||
before_action :set_article, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@articles = Article.all | ||
end | ||
|
||
def index | ||
@articles = Article.all | ||
end | ||
def show | ||
end | ||
|
||
def new | ||
@article = Article.new | ||
end | ||
|
||
def create | ||
@article = Article.new(article_params) | ||
if @article.save | ||
redirect_to @article, notice: 'Article was successfully created.' | ||
else | ||
render :new | ||
def edit | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @article.update(article_params) | ||
redirect_to @article, notice: 'Article was successfully updated.' | ||
else | ||
render :edit | ||
def update | ||
if @article.update(article_params) | ||
redirect_to @article, notice: 'Article was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@article = Article.find(params[:id]) # Ищем статью по ID | ||
@article.destroy | ||
redirect_to articles_url, notice: 'Article was successfully destroyed.' | ||
end | ||
|
||
private | ||
def set_article | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def set_article | ||
@article = Article.find(params[:id]) | ||
def create | ||
@article = Article.new(article_params) | ||
if @article.save | ||
redirect_to articles_path, notice: 'Article was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def article_params | ||
params.require(:article).permit(:title, :body) | ||
params.require(:article).permit(:title, :author, :content) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,110 @@ | ||
<h1>New Article</h1> | ||
<style> | ||
|
||
<%= form_with(model: @article, local: true) do |form| %> | ||
body { | ||
background-color: #eaceb6; | ||
} | ||
|
||
.page-title { | ||
text-align: center; | ||
font-size: 2.5em; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.article-form { | ||
background-color: #8b4513; | ||
max-width: 600px; | ||
margin: 0 auto; /* Центрирование формы */ | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 8px; | ||
} | ||
|
||
.field { | ||
margin-bottom: 15px; | ||
background-color: #8b4513; | ||
} | ||
|
||
.label { | ||
display: block; | ||
font-weight: bold; | ||
margin-bottom: 5px; | ||
} | ||
|
||
.input, .textarea { | ||
width: 100%; /* Ширина на 100% */ | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
.textarea { | ||
height: 150px; /* Высота текстовой области */ | ||
} | ||
|
||
/* Если у вас есть отдельный контейнер для текстовой области, добавьте его */ | ||
.textarea-container { | ||
display: flex; /* Используем Flexbox для центрирования */ | ||
justify-content: center; /* Центрируем содержимое по горизонтали */ | ||
} | ||
|
||
/* Убедитесь, что элементы ввода и текстовые области имеют одинаковую ширину */ | ||
.input, .textarea { | ||
max-width: 100%; /* Ограничение ширины на 100% */ | ||
} | ||
|
||
.error-explanation { | ||
background-color: #f8d7da; | ||
color: #721c24; | ||
padding: 15px; | ||
border-radius: 5px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.submit-button { | ||
background-color: #007bff; | ||
color: white; | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
.submit-button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
</style> | ||
|
||
<h1 class="page-title">Новая статья</h1> | ||
|
||
<%= form_with(model: @article, local: true, html: { class: 'article-form' }) do |form| %> | ||
<% if @article.errors.any? %> | ||
<div id="error_explanation"> | ||
<div id="error_explanation" class="error-explanation"> | ||
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2> | ||
<div class="error-messages"> | ||
<ul> | ||
<% @article.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<ul> | ||
<% @article.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<div class="label"> | ||
<%= form.label :title %> | ||
</div> | ||
<div class="input"> | ||
<%= form.text_field :title %> | ||
</div> | ||
<%= form.label "Название", class: 'label' %> | ||
<%= form.text_field :title, class: 'input' %> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="label"> | ||
<%= form.label :body %> | ||
</div> | ||
<div class="input"> | ||
<%= form.text_area :body %> | ||
</div> | ||
<%= form.label "Автор", class: 'label' %> | ||
<%= form.text_field :author, class: 'input' %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label "Текст вашей статьи", class: 'label' %> | ||
<%= form.text_area :content, class: 'textarea' %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit %> | ||
<%= form.submit 'Опубликовать статью', class: 'submit-button' %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="back-link"> | ||
<%= link_to 'Back', '/' %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<h1><%= @article.title %></h1> | ||
|
||
<p><%= @article.body %></p> | ||
<p><%= @article.content %></p> | ||
|
||
<%= link_to 'Edit', edit_article_path(@article) %> | | ||
<%= link_to 'Back', '/' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.