Pergunta

This may be a dumb question, but since I don't know the answer I'm going to go ahead and ask anyway. I have an app (mobile) that is hosted on Heroku with a Rails server. I have all the basic API stuff there.

Now I have a landing page for my app that I would like to host on this server. It's a basic template, but the problem is that it has a non MVC structure, i.e it is just HTML, CSS and a few jQuery/JS plugins.

How do I host this on my existing server, which has an App --> Controllers, Models, Views, Assets... type of structure?

Foi útil?

Solução

If you want to serve static pages in rails you can create a Static controller and Static views and route the actions in the Static controller to your Static views. Note there will be no associated static model. For example:

controllers/static_controller.rb

class StaticController < ApplicationController
  def landing_page
  end

  def another_page
  end
end

views/landing_page.html

<title> <h1>Landing Page stuff</h1> </title>

views/landing_page.html

<title> <h1>Another Static Page</h1> </title>

config/routes.rb

Project::Application.routes.draw do
  root :to => "static#landing_page"

  match '/another_page', to: 'static#another_page', via: 'get'

end

Outras dicas

Firstly, if you want to do something out of scope of MVC, you may wish to check out other frameworks. IonicFramework recently just attracted funding & is an HTML5 mobile app framework


Static Pages

If your question is about loading static pages in Rails, you have to remember Rails is not tied into using a DB. The MVC structure is that - a structure

The Rails way of doing things is as such:

HTTP Request > ActionDispatch::Routing > Controller::Action

This means if you set up a route as follows:

#config/routes.rb
get "landing_page", to: "static#action"
get "static_page", to: "static#static_action"

You'll be able to see how to set up the controller from Steve's answer

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top