6 Day ~7 Day
페이지 정보
작성자 개발관리자 작성일 22-04-25 17:01 조회 227 댓글 1본문
지난번에 만든 로또 놀라운 결과 발표
데이터베이스의 개념과 CRUD 게시판 만들기
https://www.youtube.com/watch?v=2CHkds265N8&list=PLU9-uwewPMe19RQNzTdSdewSgw92UI1kl&index=18
세상에서 가장 쉬운 인공지능 만들기 1탄 | Teachable Machine으로 AI 과일도감 제작하기
https://www.youtube.com/watch?v=USQGTW34lO8&list=PLU9-uwewPMe19RQNzTdSdewSgw92UI1kl&index=21
rails g scaffold Post title:string content:string
rails db:migrate
rails g controller board index
get '/board', to: 'board#index'
rails g model post
------ routes.rb ------
Rails.application.routes.draw do
get '/board', to: 'board#index'
post '/create', to: 'board#create'
get '/edit', to: 'board#edit'
post '/update', to: 'board#update'
get '/delete', to: 'board#delete'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
----- _posts.rb ----------
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.string :title
t.text :content
t.timestamps
end
end
end
-------- index.html.erb ----
<form action="/create" method="post">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
제목 :
<input type="text" name="title"><br>
내용 :
<input type="text" name="content"><br><br>
<input type="submit" value="Submit">
</form>
<%@posts.each do |post| %>
<h1> 제목 : <%=post.title%></h1>
<p>내용 : <%=post.content%></p>
<a href="/edit?id=<%=post.id%>">수정하기</a>
<a href="/delete?id=<%=post.id%>">삭제하기</a>
<hr>
<% end %>
--- board_controllerl.rb ----
class BoardController < ApplicationController
def index
@posts = Post.all
end
def create
title1 = params[:title]
content1 = params[:content]
Post.create(title:title1, content: content1)
redirect_to '/board'
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
@post.title = params[:title]
@post.content = params[:content]
@post.save
redirect_to '/board'
end
def delete
@post = Post.find(params[:id])
@post.destroy
redirect_to '/board'
end
end
---- edit.html.erb -----
<form action="/update" method="post">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
<input name="id" value="<%= @post.id %>" type="hidden">
제목 :
<input type="text" name="title" value="<%= @post.title %>"><br>
내용 :
<input type="text" name="content" value="<%= @post.content %>"><br><br>
<input type="submit" value="Submit">
</form>
데이터베이스의 개념과 CRUD 게시판 만들기
https://www.youtube.com/watch?v=2CHkds265N8&list=PLU9-uwewPMe19RQNzTdSdewSgw92UI1kl&index=18
세상에서 가장 쉬운 인공지능 만들기 1탄 | Teachable Machine으로 AI 과일도감 제작하기
https://www.youtube.com/watch?v=USQGTW34lO8&list=PLU9-uwewPMe19RQNzTdSdewSgw92UI1kl&index=21
rails g scaffold Post title:string content:string
rails db:migrate
rails g controller board index
get '/board', to: 'board#index'
rails g model post
------ routes.rb ------
Rails.application.routes.draw do
get '/board', to: 'board#index'
post '/create', to: 'board#create'
get '/edit', to: 'board#edit'
post '/update', to: 'board#update'
get '/delete', to: 'board#delete'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
----- _posts.rb ----------
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.string :title
t.text :content
t.timestamps
end
end
end
-------- index.html.erb ----
<form action="/create" method="post">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
제목 :
<input type="text" name="title"><br>
내용 :
<input type="text" name="content"><br><br>
<input type="submit" value="Submit">
</form>
<%@posts.each do |post| %>
<h1> 제목 : <%=post.title%></h1>
<p>내용 : <%=post.content%></p>
<a href="/edit?id=<%=post.id%>">수정하기</a>
<a href="/delete?id=<%=post.id%>">삭제하기</a>
<hr>
<% end %>
--- board_controllerl.rb ----
class BoardController < ApplicationController
def index
@posts = Post.all
end
def create
title1 = params[:title]
content1 = params[:content]
Post.create(title:title1, content: content1)
redirect_to '/board'
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
@post.title = params[:title]
@post.content = params[:content]
@post.save
redirect_to '/board'
end
def delete
@post = Post.find(params[:id])
@post.destroy
redirect_to '/board'
end
end
---- edit.html.erb -----
<form action="/update" method="post">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
<input name="id" value="<%= @post.id %>" type="hidden">
제목 :
<input type="text" name="title" value="<%= @post.title %>"><br>
내용 :
<input type="text" name="content" value="<%= @post.content %>"><br><br>
<input type="submit" value="Submit">
</form>





김미경님의 댓글
김미경 작성일<div>Teachable Machine Image Model</div>
<button type="button" onclick="init()">Start</button>
<div id="webcam-container"></div>
<div id="label-container"></div>
<script src="tfjs@1.3.1/dist/tf.min.js"" TARGET="_blank" rel="nofollow">https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.3.1/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"></script>
<script type="text/javascript">
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
// the link to your model provided by Teachable Machine export panel
const URL = "./my_model/";
let model, webcam, labelContainer, maxPredictions;
// Load the image model and setup the webcam
async function init() {
const modelURL = URL + "model.json";
const metadataURL = URL + "metadata.json";
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// or files from your local hard drive
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();
// Convenience function to setup a webcam
const flip = true; // whether to flip the webcam
webcam = new tmImage.Webcam(200, 200, flip); // width, height, flip
await webcam.setup(); // request access to the webcam
await webcam.play();
window.requestAnimationFrame(loop);
// append elements to the DOM
document.getElementById("webcam-container").appendChild(webcam.canvas);
labelContainer = document.getElementById("label-container");
for (let i = 0; i < maxPredictions; i++) { // and class labels
labelContainer.appendChild(document.createElement("div"));
}
}
async function loop() {
webcam.update(); // update the webcam frame
await predict();
window.requestAnimationFrame(loop);
}
// run the webcam image through the image model
async function predict() {
// predict can take in an image, video or canvas html element
const prediction = await model.predict(webcam.canvas);
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
labelContainer.childNodes[i].innerHTML = classPrediction;
}
}
</script>