./bin/rails importmap:install

This commit is contained in:
Ryan W
2021-09-26 15:22:36 -07:00
parent 536a7d88cb
commit bea88d4d33
31 changed files with 484 additions and 19 deletions
+69
View File
@@ -0,0 +1,69 @@
class ArticlesController < ApplicationController
before_action :set_article, only: %i[ show edit update destroy ]
# GET /articles or /articles.json
def index
@articles = Article.all
end
# GET /articles/1 or /articles/1.json
def show
end
# GET /articles/new
def new
@article = Article.new
end
# GET /articles/1/edit
def edit
end
# POST /articles or /articles.json
def create
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: "Article was successfully created." }
format.json { render :show, status: :created, location: @article }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /articles/1 or /articles/1.json
def update
respond_to do |format|
if @article.update(article_params)
format.html { redirect_to @article, notice: "Article was successfully updated." }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# DELETE /articles/1 or /articles/1.json
def destroy
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url, notice: "Article was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_article
@article = Article.find(params[:id])
end
# Only allow a list of trusted parameters through.
def article_params
params.require(:article).permit(:title, :text)
end
end
+4
View File
@@ -0,0 +1,4 @@
class WelcomeController < ApplicationController
def index
end
end
+2
View File
@@ -0,0 +1,2 @@
module ArticlesHelper
end
+2
View File
@@ -0,0 +1,2 @@
module WelcomeHelper
end
-2
View File
@@ -1,3 +1 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
+2
View File
@@ -0,0 +1,2 @@
class Article < ApplicationRecord
end
+15
View File
@@ -0,0 +1,15 @@
<div id="<%= dom_id article %>" class="scaffold_record">
<p>
<strong>Title:</strong>
<%= article.title %>
</p>
<p>
<strong>Text:</strong>
<%= article.text %>
</p>
<p>
<%= link_to "Show this article", article %>
</p>
</div>
@@ -0,0 +1,2 @@
json.extract! article, :id, :title, :text, :created_at, :updated_at
json.url article_url(article, format: :json)
+27
View File
@@ -0,0 +1,27 @@
<%= form_with(model: article) do |form| %>
<% if article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% article.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :text %>
<%= form.text_area :text %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
+10
View File
@@ -0,0 +1,10 @@
<h1>Editing article</h1>
<%= render "form", article: @article %>
<br>
<div>
<%= link_to "Show this article", @article %> |
<%= link_to "Back to articles", articles_path %>
</div>
+9
View File
@@ -0,0 +1,9 @@
<p id="notice"><%= notice %></p>
<h1>Article</h1>
<div id="articles">
<%= render @articles %>
</div>
<%= link_to "New article", new_article_path %>
+1
View File
@@ -0,0 +1 @@
json.array! @articles, partial: "articles/article", as: :article
+9
View File
@@ -0,0 +1,9 @@
<h1>New article</h1>
<%= render "form", article: @article %>
<br>
<div>
<%= link_to "Back to articles", articles_path %>
</div>
+10
View File
@@ -0,0 +1,10 @@
<p id="notice"><%= notice %></p>
<%= render @article %>
<div>
<%= link_to "Edit this article", edit_article_path(@article) %> |
<%= link_to "Back to articles", articles_path %>
<%= button_to "Destroy this article", article_path(@article), method: :delete %>
</div>
+1
View File
@@ -0,0 +1 @@
json.partial! "articles/article", article: @article
+3
View File
@@ -0,0 +1,3 @@
<h1>Welcome</h1>
<%= link_to "Articles", articles_path %>