The page found in app/views/posts/ Īnd of course the _ partial found in app/views/posts/_ We render a partial which gets used to but the and pages within the posts views folder. Kicking things off is the index page:įind this code in app/views/posts/ We have a new file for each route within our application. Our posts views folder is also straightforward. Repeat all CRUD actions with a final controller as follows (follow along on the video for a complete explanation) Update routes file in app/config/routes.rb to use resources :posts and also add root: "posts#index"Ĭreate index action on your posts_controller.rb file and view inside app/views/posts/ The Post controller helps handle our actions when we create, edit, show, update and delete posts on the blog. If you use Simple Form with Bootstrap or Foundation you likely need even less markup than this. Here I add Bulma specific classes to get Simple Form to play nice with the CSS framework. Our final post form partial is as follows. guard(main)> 00:00:00 - INFO - Browser connected. 00:00:00 - INFO - LiveReload is waiting for a browser to connect.Ġ0:00:00 - INFO - Guard is now watching at '/path/to/your/project/' If your console reads back something similar to the following, then you are in good shape. Make sure your browser extension is active when navigating to your app. We use bundle exec as a prefix here so guard has access to all of our dependences in the project. To start the "watching" process within your project directory. Restart your server once more for good measure. # comment this whole block out as we won't be making use if minitest Gem 'guard-livereload', '~> 2.5', '>= 2.5.2', require: falseīe sure to comment out the following block in the `Guardfile if it gets generated for your project. # reload the browser after changes to assets/helpers/tests Make sure to run bundle and restart your server. ![]() Add the following within the development space of the Gemfile.Download the livereload browser extension for your browser.I use this to automatically reload the browser when Guard senses changes within the code base. Guard LiveReload - This gem depends on the Guard gem.# Guard is a command line tool to easily handle events on file system modifications. Make sure to run bundle and restart your server (covered in the video). Guard - This gem is useful for live reloading our scss, js, css, and erb files, although it's capable of much more! Guard is required for the Guard LiveReload gem to workĪdd the following within the development space in the Gemfile. I'm a big fan of Bulma so we will be using it a lot throughout this series. ![]() Gems used in the projectīetter Errors - Easier on the eyes when it comes to errors.īulma - Most of the time I would roll my own CSS or just use bits of a framework. For this project, we make use of a few gems of which help make my life a bit easier as I build out applications. I touch on things such as routing, controllers, views, models, migrations, relations, and more. Ultimately, the point of this tutorial and video is to help anyone new to the framework understand how it operates as well as the necessary conventions required to create a blog using Ruby on Rails. My goal was to ease newcomers into the conventions, methods, and code patterns that helped me best when I first dove in. I'm sure new features and improvements to our blog are easy to spot as I guide you through the process of building it. With Ruby on Rails, the possibilities are pretty endless in terms of what you can build. Comments will be able to be created and deleted. There will also be comments associated with each individual blog post. Each blog post will be able to be created, read, edited, and deleted. To easily demonstrate the principles of working with Ruby on Rails I chose to build a basic blog. Working together, both Ruby and Rails lend us a hand to generate a fairly simple MVC pattern built on top of a CRUD approach when working with dynamic data.ĭownload the source code Kicking things off with a blog Building a blog with comments using Ruby on Rails is a foundational exercise I went through to learn more about the framework.
0 Comments
Leave a Reply. |