×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
・追加
a:
task=Task.new(params.require(:task).permit(:name, :description))
b:
task = Task.new
task.attributes = {name: params.require(:task).permit(:name)[:name],
description: params.require(:task).permit(:description)[::description]}
if task.save!
・update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
a:
task=Task.new(params.require(:task).permit(:name, :description))
b:
task = Task.new
task.attributes = {name: params.require(:task).permit(:name)[:name],
description: params.require(:task).permit(:description)[::description]}
if task.save!
・update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
PR
_form.html.erb
共通ルーチン
newとedit
共通ルーチン
<%= form_for @task do |t| %>
<div class="container">
<div class="row">
<div class="col-1 text-white bg-dark" >名前</div>
<div class="col-1"> <%= t.text_field :name,placeholder: 'enter name' %></div>
</div>
<div class="row">
<% if @task.errors.messages[:name].any? %>
<%= @task.errors.messages[:name][0] %>
<% end %>
</div>
<div class="row">
<div class="col-1 text-white bg-dark" >内容</div>
<div class="col-5"><%= t.text_area :description,placeholder: 'enter description' %></div>
</div>
<div class="row">
<% if @task.errors.messages[:description].any? %>
<%= @task.errors.messages[:description][0] %>
<% end %>
</div>
<div class="row">
<%= t.hidden_field :dat1 ,value:'hogehoge' %>
</div>
<div class="row">
<div class: 'btn btn-warning btn-sm > <%= t.submit %></div>|
<%= link_to 'Back', tasks_path , class: 'btn btn-warning btn-sm' %>
<% end %>
newとedit
<h1>追加</h1>
<%= render 'form' %>
controllerの編集
class TasksController < ApplicationController
def index
@tasks = Task.all.order(created_at: 'desc')
end
def show
@task = Task.find(params[:id])
end
def new
@task = Task.new
end
def edit
@task = Task.find(params[:id])
end
def create
#task_params
task=Task.new(params.require(:task).permit(:name, :description))
#task = Task.new
# task.attributes = {name: params[:task][:name], description: params[:task][:description]}
#@task= Task.new(task_params )
#@task = Task.new(task_params)
#if @task.save
if task.save!
#redirect
flash[:notice] ="タスク 「#{task.name}」を登録しました"
redirect_to tasks_path
else
#render plain:@post.errors.inspect
render :new
end
end
def update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
# @task = Task.find(params[:id])
# if @task.update(task_params)
flash[:notice] ="タスク 「#{@task.name}」を更新しました"
redirect_to tasks_path
else
render 'edit'
end
end
def destroy
task = Task.find(params[:id])
task.destroy
flash[:notice] ="タスク 「#{task.name}」を削除しました"
redirect_to tasks_path
end
private
def task_params
params.require(:task).permit(:name,:description,:dat1)
end
end
class TasksController < ApplicationController
def index
@tasks = Task.all.order(created_at: 'desc')
end
def show
@task = Task.find(params[:id])
end
def new
@task = Task.new
end
def edit
@task = Task.find(params[:id])
end
def create
task_params
task = Task.new
task.attributes = {name: params[:task][:name], description: params[:task][:description]}
#@task= Task.new(task_params )
#@task = Task.new(task_params)
#if @task.save
#if @task.save
if task.save!
#redirect
flash[:notice] ="タスク 「#{task.name}」を登録しました"
redirect_to tasks_path
else
#render plain:@post.errors.inspect
render :new
end
end
def update
@task = Task.find(params[:id])
if @task.update(params.require(:task).permit(:name, :description))
# @task = Task.find(params[:id])
# if @task.update(task_params)
flash[:notice] ="タスク 「#{@task.name}」を更新しました"
redirect_to tasks_path
else
render 'edit'
end
end
def destroy
task = Task.find(params[:id])
task.destroy
flash[:notice] ="タスク 「#{task.name}」を削除しました"
redirect_to tasks_path
end
private
def task_params
params.require(:task).permit(:name,:description,:dat1)
end
end
Index.html.rebの編集
<h1>一覧表示</h1>
<h2>
<%= link_to '新規追加' ,new_task_path, class: 'btn btn-primary' %>
</h2>
<% if flash[:notice] %>
<p><%= flash[:notice] %></p>
<% end %>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr class ="table-primary">
<th style="width: 20%">name
</th>
<th style="width: 60%">description
</th>
<th style="width: 20%">
</th>
</tr>
</thead>
<% @tasks.each do |task| %>
<tr>
<td>
<%=link_to task.name ,task_path(task.id) %>
</td>
<td>
<%= task.description %>
</td>
<td>
<%=link_to '[変更]', edit_task_path(task.id) , class: 'btn btn-warning btn-sm' %>|
<%=link_to '[削除]', task_path(task.id), class: 'btn btn-danger btn-sm',method: :delete,data:{confirm:'Sure?'} %>
</td>
</tr>
<% end %>
</table>
VB.NETでZXingを使ってQRコード生成
詳細は以下を参照するとして
https://github.com/micjahn/ZXing.Net/tree/master/docs
VS2017で実行テスト
AndroidでQRコードreadの定番はZXingなので、ZXingをテストで使用
1.vb.netでwindowsアプリのプロジェクトを作成
2.ツール Nugetパッケージマネージャー>>ソリューションのNugetパッケージマネージャ
の管理>>検索でZXing>>ZXing.netを選択しインストール
3.form1にピクチャーボックスを作成
4.ボタンを配置 以下をコーディング
Dim Wcode As New ZXing.BarcodeWriter
'種類
Wcode.Format = ZXing.BarcodeFormat.QR_CODE
'大きさ
詳細は以下を参照するとして
https://github.com/micjahn/ZXing.Net/tree/master/docs
VS2017で実行テスト
AndroidでQRコードreadの定番はZXingなので、ZXingをテストで使用
1.vb.netでwindowsアプリのプロジェクトを作成
2.ツール Nugetパッケージマネージャー>>ソリューションのNugetパッケージマネージャ
の管理>>検索でZXing>>ZXing.netを選択しインストール
3.form1にピクチャーボックスを作成
4.ボタンを配置 以下をコーディング
Dim Wcode As New ZXing.BarcodeWriter
'種類
Wcode.Format = ZXing.BarcodeFormat.QR_CODE
'大きさ
Wcode.Options.Height = 80
Wcode.Options.Width = 80
'マージン
Wcode.Options.Margin = 1
'文字
Wcode.Options.Hints(ZXing.EncodeHintType.CHARACTER_SET) = "Shift_JIS"
'エラー訂正
Wcode.Options.Hints(ZXing.EncodeHintType.ERROR_CORRECTION) = ZXing.QrCode.Internal.ErrorCorrectionLevel.L
Wcode.Options.Width = 80
'マージン
Wcode.Options.Margin = 1
'文字
Wcode.Options.Hints(ZXing.EncodeHintType.CHARACTER_SET) = "Shift_JIS"
'エラー訂正
Wcode.Options.Hints(ZXing.EncodeHintType.ERROR_CORRECTION) = ZXing.QrCode.Internal.ErrorCorrectionLevel.L
'実行
PictureBox1.Image = Wcode.Write("2019010212345678")
5.印刷の時はこのピクチャーボックスを印字
追記VB2019でも同じ手順で作成可能
追記PHPはhttps://github.com/khanamiryan/php-qrcode-detector-decoder
PictureBox1.Image = Wcode.Write("2019010212345678")
5.印刷の時はこのピクチャーボックスを印字
追記VB2019でも同じ手順で作成可能
追記PHPはhttps://github.com/khanamiryan/php-qrcode-detector-decoder