Embedding Ruby on Rails Project into HTML File - html

Problem:
I completed the Ruby on Rails "Hello World" tutorial here which walks you through how to build a blog. Now, I want to see if I can embed the work that I've done into an html file.
What I've looked into:
However, I am not exactly sure how to go about that. I looked into embedded ruby and found a good tutorial/explanation on Tutorials Point and some other sites on Google. Those examples show how to write ruby code within the file though. That seems great if I'm only writing a few lines, but I want to incorporate an entire project.
I also found a link on writing templates, but that didn't seem like what I was looking for either.
Question:
Is there a way I can add my blog to a static html/css site that I've already created?
Something like <% link railsblog %>? Or is there any other way to incorporate the project on an html page?
Thanks for any advice!

So you have a Static Html-Css website. You want to add a blog to it. Right?
The thing is, a Ruby on Rails project (eg: your blog) is not something 'additional' that you can add to a website.
It is a very powerful framework that allows you to build an ENTIRE website within the project.
Once you have a Rails project (your blog) running, you can put all your other existing static html, css, js files into the Rails PUBLIC folder.
Now if start up your server ( run rails server ), and try to access your other pages, you should see them. eg: ( localhost:3000/my-page-name.html )
Now to get localhost:3000 to point to your actual homepage.
In your 'routes.rb' file, add route:
root 'main#index'
Create a new Controller file in controllers:
class MainController < ApplicationController
def index
redirect_to '/index.html'
end
end
You'll have to learn a couple of things about Rails if you're planning to move your entire website to Rails or if you're curious.
This should help you get started.
Or if you're not looking to learn an entire framework for a blog, try this.
Good luck!

I think the solution is to create a partial html.erb file, for intance:
_fileName.html.erb
then you can put inside your html code and render by calling:
<%= render 'layouts/fileName' %>

You can always render a file (e.g static form public folder) or render a view if it has a respective controller/action. Remember that to render a view you need right routing in routes.rb except rendering partials file which should start with underscore e.g _partial.html.erb
If you want to call some resource embeded in other web site you can always use but it has nothing in common with rails.

Related

Webpack 4 - HTML partials

I'm working on Webpack/Gulp enviroment, and I wanna add function to include HTML partials like header and footer inside other page views.
The best solution for this will be like in PHP, include file and it's fine.
I used html-webpack-plugin, html-loader and gulp-file-include but this not working for me or this build one file from this partials and on development mode on local server i can't look to results because this partial before build not working.
Someone maybe have a solution or think for this?

How do I add an HTML page my front end developer built to a rails project?

Our front end developer built out an html page (our About.html page) with javascript functionality using CSS styling after given the design spec.
I have a rails project I'd like to add this page to.
I've noticed that in the rails file system, under app/views/static_pages we have 1 page, home.html.haml
I'm wondering if I should be converting this file (or files) she's built to HAML.
Assuming you want to add the About page as a new page and not replace the existing Home page, you'll need to do the following:
1) Add a route to the new page in routes.rb that looks something like this:
get "about" => "static_pages#about"
2) Add a method to app/controllers/static_pages_controller.rb that looks like this:
def about
end
3) Copy the about.html file to app/views/static_pages/about.html.erb.

Adding Django to already made HTML/css site

Hey guys so I been looking into making a site and was going to learn php for it but after a lot of research I saw how I can use Django for the backend of the site so I already started creating a site with HTML/css/js before I decide to use Django. Is there any possible way you can connect HTML/css to Django or do I need to re write everything in Django. I did look at some tutorials and saw how all the HTML was in django and I also did try looking it up too but couldn't find the right answer I'm looking for. If anyone could tell me I'll be very appreciated!! Thanks!
You can connect it. Django is a backend framework, all it does in the frontend is print data.
Read about templates in Django. Templates are basically html files with dynamic content.
Take the template my_template.html:
My first name is {{ first_name }}.
You render it like this:
from django.template.loader import render_to_string
rendered = render_to_string('my_template.html', {'first_name': 'Cesar'})
It will output:
My first name is Cesar.
Make sure to read the whole intro tutorial to Django.
Note: There are many ways to use a template, this was just a little example.
All you need to move from your old project to new one created with django-admin startproject are:
HTML templates adapted to django template language configured as described here: https://docs.djangoproject.com/en/1.10/topics/templates/
css/img/js files to static folder
After it you need to replace old href attributes to something like <a href="{% url "Index" %}"> and insert correct paths (includes static url) of css/img/js files to hmtl

Where do I put previously made HTML files in a Rails application?

I made a website with Twitter bootstrap and the design is finished in terms of all the HTML and CSS.
Now I need to add functions like making an account and blogging. I decided to use Ruby on Rails to do this, but I have no idea where to put the files and how to connect them.
So far I have figured out that I want to put them in the "views" folder and have it say, for example, "index.html.erb" but I don't know if that goes into another folder in "views" or how any of that works.
I also don't know where to put all the CSS and JavaScript incorporated with bootstrap.
Following Rails conventions, views should go in a dir that mirrors the model name (plural), which also aligns with the controller name. i.e. model = user, views dir = users, controller = users_controller.rb. You should read through at least the first few Rails guides; esp this layout and rendering one:
RE the bootstrap portion of this question, just use the bootstrap-sass gem and follow the instructions for including it in your application.scss and application.js.

Which directory do images and stylesheets go in for Ruby on Rails HTML pages?

I finished my Ruby on Rails project and I get extra credit for making it "look good." I made an HTML template with some images and css styling on my local machine (not the RoR server). I've tested it out in plain HTML and it looks good.
I can't figure out how to incorporate it into my RoR project though. I thought i'd be able to create a directory in my views, called "images" to hold the images for my template.
Before transferring all of the code for my RoR to the tags for my template, I wanted to make sure the images were in the right location. I added to my index.html.erb file, but it won't display. I tried moving that images directory to a few other directories and tried again, same thing!
I thought it would be easy to incorporate a template haha but now I'm thinking not?
Is there a way to simply do this like an ordinary HTML website?
There are two main options for this...
You can use the asset pipeline and serve up assets from a location like app/assets... So, app/assets/images.
You can put them in public/images and just serve them up that way as well.
If you feel like learning a bit more, I'd dig into the asset pipeline. If you're just ready to be done, public/images for a small project should work just fine. :)