something to play with

This commit is contained in:
Torsten 2023-02-08 11:30:19 +02:00
parent 208b3b44cb
commit c9031f9dd2
9 changed files with 123 additions and 1 deletions

View File

@ -0,0 +1,58 @@
class ImagesController < ApplicationController
before_action :set_image, only: %i[ show edit update destroy ]
# GET /images
def index
@images = Image.all
end
# GET /images/1
def show
end
# GET /images/new
def new
@image = Image.new
end
# GET /images/1/edit
def edit
end
# POST /images
def create
@image = Image.new(image_params)
if @image.save
redirect_to @image, notice: "Image was successfully created."
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT /images/1
def update
if @image.update(image_params)
redirect_to @image, notice: "Image was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /images/1
def destroy
@image.destroy
redirect_to images_url, notice: "Image was successfully destroyed."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end
# Only allow a list of trusted parameters through.
def image_params
params.fetch(:image, {})
end
end

View File

@ -0,0 +1,2 @@
class Image
end

View File

@ -0,0 +1,17 @@
<%= form_with(model: image) do |form| %>
<% if image.errors.any? %>
<div style="color: red">
<h2><%= pluralize(image.errors.count, "error") %> prohibited this image from being saved:</h2>
<ul>
<% image.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@ -0,0 +1,2 @@
<div id="<%= dom_id image %>">
</div>

View File

@ -0,0 +1,10 @@
<h1>Editing image</h1>
<%= render "form", image: @image %>
<br>
<div>
<%= link_to "Show this image", @image %> |
<%= link_to "Back to images", images_path %>
</div>

View File

@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>
<h1>Images</h1>
<div id="images">
<% @images.each do |image| %>
<%= render image %>
<p>
<%= link_to "Show this image", image %>
</p>
<% end %>
</div>
<%= link_to "New image", new_image_path %>

View File

@ -0,0 +1,9 @@
<h1>New image</h1>
<%= render "form", image: @image %>
<br>
<div>
<%= link_to "Back to images", images_path %>
</div>

View File

@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>
<%= render @image %>
<div>
<%= link_to "Edit this image", edit_image_path(@image) %> |
<%= link_to "Back to images", images_path %>
<%= button_to "Destroy this image", @image, method: :delete %>
</div>

View File

@ -1,3 +1,3 @@
Rails.application.routes.draw do
mount VueR::Engine => "/vue_r"
resources :images
end