投稿時間:2022-02-23 10:22:40 RSSフィード2022-02-23 10:00 分まとめ(23件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… iTunes Storeの「今週の映画」、今週は「イップ・マン 完結」(レンタル102円) https://taisy0.com/2022/02/23/153626.html apple 2022-02-23 00:36:12
IT 気になる、記になる… イオシス、「Surface Duo 2」の128GBモデルの未使用品を167,800円で販売中 https://taisy0.com/2022/02/23/153624.html surface 2022-02-23 00:33:32
TECH Engadget Japanese 『Fall Guys』アップデートでクロスプレイ強化。PC / PS混成チーム結成が可能に https://japanese.engadget.com/fall-guys-supports-full-cross-play-005054399.html fallguys 2022-02-23 00:50:54
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] ディズニーストア、パジャマ姿のミッキーなど「ベッド周りのアイテム」を展開 https://www.itmedia.co.jp/business/articles/2202/23/news023.html itmedia 2022-02-23 09:45:00
TECH Techable(テッカブル) 分身ロボット「OriHime」を通じて14人の演者と女優が共演、朗読劇『星の王子さま』制作 https://techable.jp/archives/173712 orihime 2022-02-23 00:00:29
python Pythonタグが付けられた新着投稿 - Qiita 「新・明解Pythonで学ぶアルゴリズムとデータ構造」で勉強日記#17 https://qiita.com/kato_squalldeka/items/309a28bd0f616f676a60 レジの行列のイメージキューに追加する操作をエンキュー、取り出す操作をデキューと呼び、取り出される側を先頭、データが押し込まれる側を末尾と呼びます。 2022-02-23 09:40:05
python Pythonタグが付けられた新着投稿 - Qiita Chalice on Local https://qiita.com/akiraabe/items/f8f85971e47078b46f8d 通常のデバッグと同様ですまとめ今回は、ChaliceonLocalということで、ローカルでの実行とデバッグを行いました。 2022-02-23 09:25:31
AWS AWSタグが付けられた新着投稿 - Qiita AWS CDKでECS/FargateとRDSを作成 https://qiita.com/akiraabe/items/f52161f54dcb75c7811f そのための検証環境が必要だったため、CDKで作るのが効率が良さそうと考えて、CDKも試してみたという背景があります。 2022-02-23 09:43:14
AWS AWSタグが付けられた新着投稿 - Qiita 一般通過大学生がAWSを勉強する話 https://qiita.com/KMNMKT/items/b90afb2beb91cd5e117d ここはもしかしてスパイの本部で、自分にはわからない暗号を使って会話してるのだろうかという錯乱っぷりを見せつつ、これは体系的に学ぶしかないなと腹をくくりました。 2022-02-23 09:18:21
AWS AWSタグが付けられた新着投稿 - Qiita AWS公式資料で挑むSCS認定(4)-対象サービス攻略 https://qiita.com/mingchun_zhao/items/ba73f37e1d3b50facffc AWS公式資料で挑むSCS認定対象サービス攻略前回AWS公式資料で挑むSCS認定対象サービス攻略はじめに今回から、サービスを一つずつ理解していきますが、その前に、それぞれの目的や依存関係を加味し、勉強順つけようと思います。 2022-02-23 09:12:23
海外TECH DEV Community Building a To-Do List Using Hotwire and Stimulus https://dev.to/software_writer/building-a-to-do-list-using-hotwire-and-stimulus-120i Building a To Do List Using Hotwire and StimulusNote This is a really long article If you prefer video and want to build this along with me you can watch a recording on YouTube I also uploaded the code to Github There s nothing like building a simple run of the mill to do list when learning a new framework It teaches you the basics of creating reading updating and deleting data from various levels of the technology stack including the front end back end and database This post explains how to build such a list using the new Hotwire and Stimulus frameworks from Basecamp We will start with a new Rails app from scratch and learn about Hotwire and Stimulus as we build our list I am also going to use Tailwind to style our app but it s not a requirement and the code examples should still work without it But if you haven t worked with Tailwind I highly recommend that you give it a try Before we start coding this is a quick preview of what we are going to build It s a simple CRUD application You can add new tasks edit existing ones delete a task and also complete them I ll assume that you have installed the required dependencies for building a Rails app If not just follow the getting started guide and you should be all set For this application I will use the following stack Ruby on RailsHotwire Turbo Drive Stimulus Sqlite Tailwind CSSWith that out of the way let s start by creating a new Rails app Step Create a new Rails applicationRun the following command to create a new Rails application in a new terminal window I will call my app taskify ➜rails new taskify➜cd taskifyOpen the app in your favorite editor I will use Rubymine ➜mine Let s run the app to make sure everything is set up correctly Use the following command to start the server and visit the https localhost URL to see your app ➜bin rails server If everything works Rails should greet you with the following screen Step Install TailwindNow you could build this task manager without Tailwind just using plain CSS but since I started learning Tailwind I ve gotten fond of it and like to use it in all my projects If you don t want to use it I highly suggest that you give it a try the rest of the tutorial should still work for you First install the tailwindcss rails gem that makes the setup painless ➜bin bundle add tailwindcss railsThen run the Tailwind installer which will set up Tailwind for you additionally setting up the foreman which makes running the Tailwind very easy For more details check out my post on Foreman ➜bin rails tailwindcss installThe next step is to configure the template paths in the config tailwind config js file Tailwind watches these files to generate the final CSS However the tailwindcss rails gem does it automatically for you also setting the tailwind directives in the application tailwind css file module exports content app helpers rb app javascript js app views theme extend plugins Finally launch the Foreman script that will launch the Rails server and the Tailwind CLI to watch for changes in your HTML or ERB files and generate the CSS ➜bin dev web started with pid css started with pid Note Make sure you ve already stopped the Rails app using ctrl c that you launched earlier Otherwise the following command will throw an error saying a server is already running If everything worked you should still be greeted by the Rail logo if you reload your browser We are now ready to start building our task manager Step Create the Task resourceNow we could take the easy way out and generate a rails scaffold instead of a resource which will set up everything for us including the routes controller actions views style etc But we want to really learn how to build this task manager step by step so we will take the long route However I promise that you will learn a lot in the process We need a Task model for our task manager which has description and completed attributes So let s generate the Task resource using the rails generate resource command This command creates an empty model controller and migration to create the tasks table ➜bin rails generate resource task description string completed booleanA resource is any object that you want users to be able to access via URI and perform CRUD or some subset thereof operations on can be thought of as a resource sourceRunning this command will create a create tasks rb migration file under the db migrate directory The exact name will be different as Rails uses the timestamp to generate the name of the migration file This file should have the following content class CreateTasks lt ActiveRecord Migration def change create table tasks do t t string description limit t boolean completed t timestamps end endendLet s run the migration to create the tasks table ➜bin rails db migrate CreateTasks migrating create table tasks gt s CreateTasks migrated s If you open your SQLite database using a database viewer such as DB Browser you should see a tasks table in the database Step Set up the home routeNext we will change the routes rb file to change the home page to the tasks page instead of the Rails welcome page For this open the routes rb file and add the following directive at the top Rails application routes draw do root tasks index resources tasksendRails recommends to put the root route at the top of config routes rb as it will be matched first as this is the most popular route of most Rails applications Now restart your Rails app and reload the browser You should see an error Rails throws this error because we haven t created our index action yet We will do that in the next step Step Build the Home index PageIn addition to the migration the generate resource command should have also created an empty TasksController for you class TasksController lt ApplicationControllerendLet s create our first action that will display all the tasks In this action we will fetch all the tasks from the database class TasksController lt ApplicationController def index tasks Task all endendCreating action is not enough If you reload the page you should see a different error because we didn t create the template view corresponding to this action Let s fix that In the app views tasks directory add a file named index html erb lt h class font bold text xl gt Task Manager lt h gt If you reload the browser now the words Task Manager should greet you If you see something like this that means Tailwind is working correctly too Step Ability to create new tasksA task manager without any tasks is boring So let s add a form using which the users can add new tasks Start by creating a new task in the index action on our TasksController Our form will use this as the default task class TasksController lt ApplicationController def index tasks Task all task Task new endendNext we will create the form partial by adding a form html erb file in the app views tasks directory This form has an input field and a button to submit the task lt form with model task class mb do form gt lt div class mb gt lt form text field description placeholder Add new task class inline block shadow rounded md border border gray outline none px py mt w gt lt form submit Save class btn py ml bg blue text white gt lt div gt lt end gt Add the following code to the index html erb file to display this form partial on the home page lt h class font bold text xl gt Task Manager lt h gt lt div class mt gt lt render form task task gt lt div gt Notice that we are rendering the form as a partial so we can reuse it later possibly in a separate page that lets users add more details to a task Partials allow you to break the rendering process into more manageable chunks With a partial you can move the code for rendering a particular piece of a response to its own file Finally add some style in the application tailwind css file so our buttons look good I ve also removed the flex class on my main element in the application html erb file to keep things simple tailwind base tailwind components tailwind utilities layer components btn apply mt rounded lg py px inline block font medium cursor pointer Now reload the page You should see something like this If you add some text and click Save the page reloads However opening the Devtools shows an error in the networks tab because we are not handling form submissions on the back end Let s fix it by adding a create action on the TasksController class TasksController lt ApplicationController def create task Task new task params respond to do format if task save format html redirect to tasks url notice Task was successfully created else format html render new status unprocessable entity end end end private def task params params require task permit description endendYou might wonder why are we using task params method instead of fetching them directly from params hash This technique allows you to choose which attributes should be permitted for mass updating and thus prevent accidentally exposing that which shouldn t be exposed require is used to mark parameters as required and permit is used to set the parameter as permitted and limit which attributes should be allowed for mass updating sourceFinally update the index html erb template to show the notice message at the top lt if notice present gt lt p class py px bg green mb text green font medium rounded lg inline block id notice gt lt notice gt lt p gt lt end gt lt h class font bold text xl gt Task Manager lt h gt lt div class mt gt lt render form task task gt lt div gt Let s add a new task and hit the Save button You should see the success message saying that the task was successfully saved in the database But wait Where is my task It s not showing up because we haven t added any code on our view template to display the tasks Let s fix that by adding the following code the last div below in the index html erb file lt if notice present gt lt p class py px bg green mb text green font medium rounded lg inline block id notice gt lt notice gt lt p gt lt end gt lt h class font bold text xl gt Task Manager lt h gt lt div class mt gt lt render form task task gt lt div gt lt div id tasks gt lt h class font bold text lg mb gt Tasks lt h gt lt div class px gt lt render tasks gt lt div gt lt div gt We are again using the task partial in the lt render tasks gt statement which is a shortcut for looping over each task and rendering the task partial for that task Also remember that we had set the tasks variable in our index action on the TasksController So let s create the task partial by creating a task html erb file in the app views directory lt div class block mb gt lt task description gt lt div gt If you reload the page you will see our first task Hey we did it Go ahead and add a few more tasks At this point you might be wondering Hey you said we were going to use Hotwire in this tutorial When are we going to get to that part If so I have a surprise for you We are already using Hotwire At least a sub framework of it called Turbo Drive which is activated by default in a Rails app Notice that the browser is not doing a full page reload when we add a new task It also feels very responsive The server redirects you to the index page whenever you click the button However you can see that the browser is not reloading the page and your task shows up automatically What gives The answer is the Turbo Drive framework that s part of the Hotwire stack It s working behind the scenes to make your application faster How does Turbo Drive work Turbo Drive intercepts all clicks on anchor links to the same domain When you click a link or submit a form Turbo Drive does the following Prevent the browser from following the link Change the browser URL using the History API Request the new page using a fetch requestRender the response HTML byreplacing the current element with the responsemerging the element s content The JavaScript window and document objects and the element persist from one rendering to the next The same goes for an HTML form Turbo Drive converts Form submissions turned into fetch requests Then it follows the redirect and renders the HTML response As a result your browser doesn t have to reload and the app feels much faster To see how the app will behave without Hotwire disable the Turbo Drive framework by adding following line in the application js file Turbo session drive falseNow if you try to add a task you can verify that the browser did a full reload like traditional web applications That said some of you project managers mostly must have noticed that there s no way to complete our tasks What fun is there to keep piling more and more tasks without having a way to complete them We need a checkbox that will mark a task as complete or incomplete We will use another Hotwire framework called Stimulus to achieve this As advertised it is a modest JavaScript framework for the HTML you already have I love the way it describes itself on the home page Stimulus is a JavaScript framework with modest ambitions It doesn t seek to take over your entire front endーin fact it s not concerned with rendering HTML at all Instead it s designed to augment your HTML with just enough behavior to make it shine Step Use Stimulus to complete the tasksFirst let s wrap our task in a form to add a checkbox Add the following code in the task html erb file lt div class block gt lt form with model task class text lg inline block my w do form gt lt form check box completed class mr align middle bg gray border gray focus ring focus ring blue h w rounded checked bg green gt lt task description gt lt end gt lt div gt Reloading the page shows the beautiful checkbox next to our task Next we will add a data controller attribute in our index html erb template I have skipped the rest of the code for brevity You are only adding the data controller tasks attribute on the div element rendering the tasks lt div class px data controller tasks gt lt render tasks gt lt div gt In Stimulus we mark our elements of interest by annotating their data attributes such as data controller and data action Stimulus continuously monitors the page waiting for HTML data controller attributes to appear For each attribute Stimulus looks at the attribute s value to find a corresponding controller class creates a new instance of that class and connects it to the element For this data controller to work we need to add a tasks controller js file in the app javascript directory Add the following code to this file import Controller from hotwired stimulus export default class extends Controller connect console log this element Stimulus calls the connect method each time it connects a controller to the document Simply reload the page and open the dev tools window to test it s working You should see the following output in the console That means Stimulus has connected the element to our controller Next we will make a back end request whenever the user clicks the checkbox For this update the task partial task html erb by adding the data attribute lt div class block gt lt form with model task class text lg inline block my w do form gt lt form check box completed data id task id action tasks toggle class mr align middle bg gray border gray focus ring focus ring blue h w rounded checked bg green gt lt task description gt lt end gt lt div gt When Rails renders this template it spits out the following HTML lt input data id data action tasks toggle class mr type checkbox value name task completed id task completed gt The data id attribute is not specific to Stimulus but we are using it to pass the task id to the controller so that we can pass it to the server The data action attribute tells Stimulus that whenever a user clicks on this checkbox call the toggle method defined on the controller in the tasks controller js file Note The data action attribute must be nested inside an element that s getting connected to the Stimulus controller In our case the task partial is rendered inside our div element in the index template That s how Stimulus knows which method to call Now add the toggle method in our tasks controller file which makes a JavaScript fetch call to the server Again Stimulus will call this method whenever the user clicks the checkbox import Controller from hotwired stimulus export default class extends Controller connect console log this element toggle e const id e target dataset id const csrfToken document querySelector name csrf token content fetch tasks id toggle method POST GET POST PUT DELETE etc mode cors no cors cors same origin cache no cache default no cache reload force cache only if cached credentials same origin include same origin omit headers Content Type application json X CSRF Token csrfToken body JSON stringify completed e target checked body data type must match Content Type header then response gt response json then data gt alert data message There are a few points to note in the above method The toggle method takes the event as a parameter We can access the checkbox element from the target property of the event We retrieve the task id from the data attribute on the element which we set earlier Then we pass the id in the URL We are passing the csrfToken in the header Read more Cross Site Request Forgery here The body contains whether the checkbox was selected or not letting the server know if the task is completed or marked incomplete With the front end ready let s add the back end code to handle this POST request from the browser There are two steps to it Add a route in the routes rb file that tells the router to call the toggle action on the TasksController whenever a POST request is made with a specific URL pattern Rails application routes draw do post tasks id toggle to tasks toggle endAdd the toggle method on the TasksController finds the task using the id and updates the completed attribute def toggle task Task find params id task update completed params completed render json message Success endYou re all set Go ahead and mark a few tasks complete of course after you ve finished them in the real world To make sure the changes were persisted in the database reload the page and you should see the completed tasks checked off Step Add the edit and delete featuresAs the last step we will allow the users of our task manager to edit and delete their tasks Let s start by adding the corresponding actions in the tasks controller rb file class TasksController lt ApplicationController def edit task Task find params id end def update task Task find params id respond to do format if task update task params format html redirect to tasks url notice Task was successfully updated else format html render edit status unprocessable entity end end end def destroy task Task find params id task destroy redirect to tasks url notice Post was successfully deleted endendThe edit action finds the task that we want to edit and the corresponding view displays the edit form Add the edit html erb file in the app views tasks directory with the following code lt div gt lt h class font bold text xl mb gt Editing Task lt h gt lt div id lt dom id task gt gt lt render form task task gt lt link to Never Mind tasks path class btn mb bg gray gt lt div gt lt div gt Finally add the edit and delete buttons next to the task in the task html erb file lt div class block gt lt form with model task class text lg inline block my w do form gt lt end gt lt link to Edit edit task path task class btn bg gray gt lt div class inline block ml gt lt button to Delete task path task method delete data action tasks delete class btn bg red gt lt div gt lt div gt That s it Reload the page and you should see our buttons to edit and delete the tasks Clicking the Delete button should delete that task without a full page reload Clicking the Edit button should show you the form with the task in it After making changes it should redirect you to the home page Again without a full page reload Turbo Drive makes the fetch request gets the response and replaces the DOM content That s it Congratulations you have just implemented a full featured CRUD task manager using Ruby on Rails and Hotwire frameworks Wow that was a really long article I hope it was helpful If you find any mistakes both in the code or my writing or know better approaches than what I have please let me know I am learning this along with you too 2022-02-23 00:06:31
海外TECH DEV Community A arte de fazer https://dev.to/boirods/a-arte-de-fazer-3gfm A arte de fazerBom este éum daqueles posts que te motivam a fazer o seu portfólio sei que játem muito post parecido e com listas do que fazer Quero registrar aqui minha opinião E a minha opinião éfaça seu portfólio mesmo que ninguém veja mesmo que ninguém elogie seu trabalho mesmo que não seja útil Faça nem que seja pela sua diversão que seja algo que vocêgoste Muitos podem dizer ah mas eu não tenho o equipamento XYZ pra não dizer marcas kkkk e com ele eu faria muito melhor Que nada a anos não tínhamos esses equipamentos tecnológicos que temos hoje e desde a época de Davinci játinhamos coisas maravilhosas como seus desenhos Se vocêquer desenvolver vocênão precisa de um computador da Nasa Se meu computador Deus me livre kkkk quebrasse hoje eu não pararia de desenvolver porque tenho um Raspberry Pi Sei que émuito limitado mas éalgo supriria minha necessidade neste momento e ainda faria algo com eletronica kkkk E sóconcluindo que mesmo que ninguém veja mesmo que ninguém fale nada E faça algo que vocêgosta algo que vocêuse algo que vocêveja depois e pense Foi legal fazer isso Mesmo que seja copiando tutoriais na internet mas por favor dêo seu toque de personalidade E éisso agradeço a todos que lerem e como disse acima mesmo que ninguém leia comente etc kkkk estou fazendo isto para treinar também a minha escrita kkkPS Isto também épra mim pra me lembrar de nunca deixar de fazer algo kkk 2022-02-23 00:05:12
ニュース @日本経済新聞 電子版 「知識も情熱もない」 統計軽視、国の人材育成進まず https://t.co/vrbmz06yXq https://twitter.com/nikkei/statuses/1496282096532598784 人材育成 2022-02-23 00:33:46
ニュース @日本経済新聞 電子版 市場に突きつけられたプーチン氏の刃(NY特急便) https://t.co/V4DKI8UPaZ https://twitter.com/nikkei/statuses/1496282094414475270 特急 2022-02-23 00:33:45
ニュース @日本経済新聞 電子版 「空気から2000リットルの水生成」米スタートアップ社長 https://t.co/eE5s7hBW3k https://twitter.com/nikkei/statuses/1496277808745975808 空気 2022-02-23 00:16:43
ニュース BBC News - Home Screaming Trees frontman Mark Lanegan dies aged 57 https://www.bbc.co.uk/news/entertainment-arts-60487917?at_medium=RSS&at_campaign=KARANGA american 2022-02-23 00:28:55
ニュース BBC News - Home Newspaper headlines: 'War threat grows' and 'punish Putin harder' call https://www.bbc.co.uk/news/blogs-the-papers-60487887?at_medium=RSS&at_campaign=KARANGA russia 2022-02-23 00:06:03
ニュース BBC News - Home Tuchel takes Lukaku 'out of the next fire' - so is Havertz Chelsea's short-term solution? https://www.bbc.co.uk/sport/football/60488084?at_medium=RSS&at_campaign=KARANGA Tuchel takes Lukaku x out of the next fire x so is Havertz Chelsea x s short term solution Thomas Tuchel says Romelu Lukaku was taken out of the next fire after starting on the bench against Lille so is Kai Havertz Chelsea s short term striker solution 2022-02-23 00:23:04
ビジネス ダイヤモンド・オンライン - 新着記事 ウクライナ緊迫、世界経済に広がるリスク - WSJ発 https://diamond.jp/articles/-/297180 世界経済 2022-02-23 09:20:00
サブカルネタ ラーブロ すごい煮干ラーメン 凪@新宿(新宿ゴールデン街) 「ラーメン 並盛」 http://ra-blog.net/modules/rssc/single_feed.php?fid=196716 新宿ゴールデン街 2022-02-23 00:21:16
北海道 北海道新聞 秋吉台の山焼き、26日に延期 積雪の影響で、山口・美祢 https://www.hokkaido-np.co.jp/article/648956/ 秋吉台国定公園 2022-02-23 09:18:00
北海道 北海道新聞 「よいとまけ」リンゴ味 23日発売 https://www.hokkaido-np.co.jp/article/648887/ 販売 2022-02-23 09:08:07
ビジネス 東洋経済オンライン 改良ロードスターの旋回性能が別物に進化した訳 後輪ブレーキを自動で掛ける「KPC」は何が凄いか | 西村直人の乗り物見聞録 | 東洋経済オンライン https://toyokeizai.net/articles/-/513373?utm_source=rss&utm_medium=http&utm_campaign=link_back 後輪ブレーキ 2022-02-23 09:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)