something to play with
This commit is contained in:
parent
208b3b44cb
commit
c9031f9dd2
58
test/dummy/app/controllers/images_controller.rb
Normal file
58
test/dummy/app/controllers/images_controller.rb
Normal 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
|
2
test/dummy/app/models/image.rb
Normal file
2
test/dummy/app/models/image.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Image
|
||||
end
|
17
test/dummy/app/views/images/_form.html.erb
Normal file
17
test/dummy/app/views/images/_form.html.erb
Normal 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 %>
|
2
test/dummy/app/views/images/_image.html.erb
Normal file
2
test/dummy/app/views/images/_image.html.erb
Normal file
@ -0,0 +1,2 @@
|
||||
<div id="<%= dom_id image %>">
|
||||
</div>
|
10
test/dummy/app/views/images/edit.html.erb
Normal file
10
test/dummy/app/views/images/edit.html.erb
Normal 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>
|
14
test/dummy/app/views/images/index.html.erb
Normal file
14
test/dummy/app/views/images/index.html.erb
Normal 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 %>
|
9
test/dummy/app/views/images/new.html.erb
Normal file
9
test/dummy/app/views/images/new.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<h1>New image</h1>
|
||||
|
||||
<%= render "form", image: @image %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Back to images", images_path %>
|
||||
</div>
|
10
test/dummy/app/views/images/show.html.erb
Normal file
10
test/dummy/app/views/images/show.html.erb
Normal 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>
|
@ -1,3 +1,3 @@
|
||||
Rails.application.routes.draw do
|
||||
mount VueR::Engine => "/vue_r"
|
||||
resources :images
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user