0

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!

7
  • 1
    render may be you looking for guides.rubyonrails.org/layouts_and_rendering.html Commented Dec 10, 2015 at 10:06
  • Thanks. I'm reading a bit about it now. It looks like I'd have to use the embedded ruby tags and then do 'render file: filename', but I need to try it out. Commented Dec 10, 2015 at 10:11
  • render file '/file_path/' in erb you need to o it <%= render file: "/path/of/the/file"> Commented Dec 10, 2015 at 10:13
  • That wasn't it. In my html, I added <%= render file: "/path/of/the/file"> with the file being index.html.erb and it just shows up as a string of text on the web page. Commented Dec 10, 2015 at 10:24
  • @JustBlossom This entire project that you're trying to incorporate, is it a static html website ? Or a dynamic one (using databases/scripting languages)? Commented Dec 10, 2015 at 10:41

3 Answers 3

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

You can also do this root to: redirect("/index.html")
Thank you so much! That is exactly what I was trying to do! I am definitely going to look into it some more. I was trivializing rails quite a bit, and I understand that's where I was going wrong. I was able to add everything like you said, then I created a link from my index file (now in the public folder) to my rails article that lists my blog posts, and it worked like a charm. Once again, thanks a bunch for a great explanation.
0

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' %>

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.