How to auto restart rails server with grunt? - ruby-on-rails

I am working with rails-api so each time i change controller or Route file i want to auto reload rails server, so new changes will be applied.
I got basic setup to work with this plugin: link, where rails start together with grunt.
The problem is i want to reload rails server each time any rails files are changed.
Is it possible to achieve?

Yes, of course. You will need to use Guard for this purpose. Please read carefully Guards official page. They're doing good job in explaining how to setup your development environment.
There are tutorials on RailsCasts and also on NetTuts.
Edit: I forgot to mention that there is second(but definitely not the last one) option to achieve this. If you start using Spring which is Rails application preloader. Read more about this on Github page.
Here is great tutorial on how to setup everything together - http://girders.org/blog/2014/02/06/setup-rails-41-spring-rspec-and-guard/

Related

Ruby on Rails run at Blogspot?

I tried to build a ruby-based website. but I want to start on blogspot which is free for beginners. can the ruby system be placed on blogspot, I am very happy if this happens.
No Blogspot does not support ruby on rails. Even it is just a blogging platform where you already have CMS to serve you. But you should have a development environment. Please try Heroku.com if you want free.
check this tutorial https://devcenter.heroku.com/articles/getting-started-with-rails5 to launch your first application on Heroku.
You can add the following lines after
rails generate controller welcome
rails generate scaffold product name 'price:decimal{7,2}'
rails db:migrate
This will create a sample application where you can do all CRUD operation on product. you can try following
rails s
Now visit localhost:3000/products
After installation on Heroku you will get your url where you can run app and do all CRUD operation. Just try it is very easy to do.
If you are working with Ruby on Rails, consider to work with another platform like Wordpress instead. But I think it takes time.

Bootstrap for Solidus frontend

I am using Solidus for the first time. I have been able to have it working as required. However, I am trying to make changes to the frontend. Although I'd rather use bootstrap 4, I could only find a way to port it with bootstrap 3 using a gem as described here.
I have followed the instruction as explained on the page. However when I make the test changes described, expecting to see the same changes, nothing happens. In fact the page is no longer structured as it was initially which I suppose is due to overwriting all.css used by spree on the app.
I am not sure why things are not working. I tried to undo changes by running rails destroy solidus_bootstrap_frontend:install but this doesn't restore the changes. Any help would be appreciated.
Thanks.
run
rails solidus_bootstrap_frontend:install
It'll tell you what files it tries to create, and will probably ask if you want to overwrite them.
Delete these files and you'll reset the appearance to how it was before you ran the command

CKeditor not showing Formatted Code

I have installed CKeditor for my Rails app and while doing the Formatting, the Formatted code does not display in the screen, instead, HTML is rendered, like this
<h2><strong>In this project</strong> you’ll create a simple blog system and learn the basics of Ruby on Rails including: Models, Views, and Controllers (MVC) Data Structures & Relationships Routing Migrations Views with forms, partials, and helpers RESTful design Using Rails plugins/gems The project will be developed in five iterations. I0: Up and Running Part of the reason Ruby on Rails became popular quickly is that it takes a lot of the hard work off your hands, and that’s especially true in starting up a project. Rails practices the idea of "sensible defaults" and will, with one command, create a working application ready for your customization. Setting the Stage First we need to make sure everything is set up and installed. See the Environment Setup page for instructions on setting up and verifying your Ruby, Rails, and add-ons. This tutorial was created with Rails 4.0.0, and may need slight adaptations for other versions of Rails. Let us know if you find something strange! From the command line, switch to the folder that will store your projects. For instance, I use /Users/jcasimir/projects/. Within that folder, run the rails command:</h2>
Use the html_safe method
So, something like:
puts my_variable.html_safe
Lots more info here: http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/

Allow user to configure Rails application for first use (ActiveRecord etc)

Before I start the process of building something from scratch I was curious if anyone else had come across a way of providing a first-time configuration wizard for a Rails application that allows the user (sysadmin) to configure aspects of the application such as the ActiveRecord configuration and the ActionMailer setup (SMTP, sender etc).
We'd like to provide a clean easy way for new installs to get setup, rather than asking clients to edit files, or run scripts on the command line.
Essentially you should be able to download the application, extract it, start it, and when you access it via the browser you're guided through the initial setup steps.
My question isn't so much around how to do this, but more has anyone already done this. My quick search for gems, plugins etc around this idea didn't turn up much.
Edit/Clarification
To clarify the scenario - this is to support "shrink-wrapped" products that are downloaded and installed on-premises by the customer's sys admin.
The first time they access our application after deploying it behind their firewall we want a friendly way of configuring the specific settings for their install, such as database etc.
An example of such a process is JIRA's setup wizard:
https://confluence.atlassian.com/display/JIRA/Running+the+Setup+Wizard
This isn't for reating new rails applications, or systemising our development process.
I like Rails Templater a lot. It is a command line tool to build a rails app. It asks you questions like "Would you like to use rspec? Pry instead of IRB?"
I have created a fork that adds authentication, twitter bootstrap and backbone.js and some other options. It is pretty easy to hack on if you have specific needs. I use it all the time and I would hate not having it.
It is of course a command line app and not usable via the browser but maybe it will still fit your needs. Or the codebase could be integrated into a client web application.
Update after comment
You may be able to bootstrap a sqlite database so the app can boot, then just using a form or a wizard to set up something that writes your database.yml and other configs, maybe by means of thor (makes appending/replacing text in files simple and is part of rails). You would need to somehow restart the rails app and migrate the database. You could keep the pg or mysql2 gem (or both) in your Gemfile or again use thor to edit them from your wizard/form.
I also recommend using rails_config as Michael suggested. With the above solution.
If I had more time to think about the problem, I may come up with something cleaner but this is how I would do it if I had to right now.
http://railswizard.org/ lets you select which gems to use. It's a very innovative use of the ui and the isotope gem to select the components. Similarly another viewpoint is this top 10 list: http://blog.teamtreehouse.com/10-must-have-ruby-gems
You'll never find a definitive list of gems as need change from person to person and over time, e.g. which database your company uses and which is the 'current' best authentication gem are both variable.
For configuration specific settings you can make the configuration less of a chore by using practices that reduce it. For example the database.yml file is usually one of the 'must be edited locally' files. Our approach for this to to exclude database.yml from source control by putting its name in our .gitignore file. We add an database.yml.example file which we copy locally to database.yml and in that file we use anchors (&) and references (*) as detailed here: http://blog.geekdaily.org/2010/08/advanced-yaml-tricking-out-your-databaseyml.html
More options for configuring other variables for each environment: http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/
The rails config gem may also help you as detailed here: How to define custom configuration variables in rails

Ruby on Rails database.yml information

I'm a designer and brand new to programming.
I have just opened my localhost and can see "Welcome aboard". It has 3 steps to complete - all of which simple to most, are complexing to me.
config/database.yml ok it wants to know my username and password. Where do I get these and where do I post them to to get them to work? I opened my database.yml and it is
SQLite version 3.x
gem install sqlite3-ruby
I hear people talking about git and all this but confused on how to do these 3 steps -
1.
Create your databases and edit config/database.yml
Rails needs to know your login and password.
2.
Use script/generate to create your models and controllers
To see all available options, run it without parameters.
3.
Set up a default route and remove or rename this file
Routes are set up in config/routes.rb.
Is this just too over my head? I wouldn't mind hiring someone to teach get it all going for me because I really want to learn to code Ruby on Rails.
Thanks!
Note - All resolved by deleting and reinstalling. Now I understand what is actually happening.
Since you're using an SQLite database, you don't need to configure any username or password to get going with the database -- the default configuration should work out of the box and creates a new database file automatically for you.
For your other questions, the Getting Started with Rails guide over at guides.rubyonrails.org is an excellent introduction that walks you through all the steps in creating a new Rails application. Start by going through this tutorial step by step -- if you get stuck somewhere along the way you can always come back here and post follow-up questions.
If you don't have any idea what a database is you should just leave database.yml alone and use the provided defaults (use sqlite, does not require a password/login). For getting started with Rails, this should be enough. Just delete the public/index.html file.
I would really recommend you to buy a book (Rails 3) (3rd edition is for Rails 2.3) which guides you through the creation of a Rails app - with a lot of examples. The guides are an alternative, but also might be a little difficult to read with close-to-none preknowledge of programming.
I think you might find Michael Hartl's Ruby on Rails Tutorial helpful. It's available for purchase as a PDF or you can view the online version for free. It covers all the major steps of developing a Rails application, including using Git.

Resources