获取现有项目并将其移至Ruby on Rails环境中

时间:2023-02-06 07:56:48

I have the front end of a website built. It is made from a number of HTML, JavaScript, and Jquery files. Is there a way to take those files and move them into a Ruby on Rails environment so that I don't need to remake everything?

我有一个网站的前端建立。它由许多HTML,JavaScript和Jquery文件组成。有没有办法获取这些文件并将它们移动到Ruby on Rails环境中,这样我就不需要重新制作所有内容了?

1 个解决方案

#1


1  

Sure. Create a new rails app (rails new app-name). Copy your existing javascript files into the Rails project at public/javascripts/. Your views/html are a bit more dependent on how you want to grow.

当然。创建一个新的rails应用程序(rails new app-name)。将您现有的javascript文件复制到public / javascripts /的Rails项目中。您的views / html更依赖于您希望如何成长。

One option is to create a single PagesController and not bother with resources/models/etc, and you would just put all of your "views" into /app/views/pages/. You don't even have to rename them to .html.erb like you would conventionally see — you can leave them as just plain html. Your routes.rb file would look something like this:

一个选项是创建一个PagesController,而不是打扰资源/模型/等,你只需将所有“视图”放入/ app / views / pages /。您甚至不必将它们重命名为.html.erb,就像您通常会看到的那样 - 您可以将它们保留为纯HTML。你的routes.rb文件看起来像这样:

get '/:action', :controller => 'pages', :as => 'page'

Which would afford you routes like "example.com/hello_world" that would route to PagesController#hello_world, rendering "app/views/pages/hello_world.html". If you want to use ERb, you can add that ".erb" suffix to your view file and then you can use the page_path helper to assemble links:

哪个路由会像“example.com/hello_world”那样路由到PagesController#hello_world,渲染“app / views / pages / hello_world.html”。如果要使用ERb,可以将“.erb”后缀添加到视图文件中,然后可以使用page_path帮助程序来组合链接:

<%= link_to 'Hello World Demo', page_path('hello_world') %>

You will still probably want to extract the common elements into a layout at app/views/layouts/application.html.erb (again, the ERb being optional).

您仍然可能希望将公共元素提取到app / views / layouts / application.html.erb中的布局(同样,ERb是可选的)。


Another route would be to actually separate your application into resources. If you have a page that lists books, for example, you could create a BooksController and put the relevant view under app/views/books/index.html. This doesn't make sense to do if you're not going to provide some additional functionality in the future, though.

另一种方法是将您的应用程序实际分离为资源。例如,如果您有一个列出书籍的页面,您可以创建一个BooksController并将相关视图放在app / views / books / index.html下。但是,如果你将来不打算提供一些额外的功能,这没有任何意义。

#1


1  

Sure. Create a new rails app (rails new app-name). Copy your existing javascript files into the Rails project at public/javascripts/. Your views/html are a bit more dependent on how you want to grow.

当然。创建一个新的rails应用程序(rails new app-name)。将您现有的javascript文件复制到public / javascripts /的Rails项目中。您的views / html更依赖于您希望如何成长。

One option is to create a single PagesController and not bother with resources/models/etc, and you would just put all of your "views" into /app/views/pages/. You don't even have to rename them to .html.erb like you would conventionally see — you can leave them as just plain html. Your routes.rb file would look something like this:

一个选项是创建一个PagesController,而不是打扰资源/模型/等,你只需将所有“视图”放入/ app / views / pages /。您甚至不必将它们重命名为.html.erb,就像您通常会看到的那样 - 您可以将它们保留为纯HTML。你的routes.rb文件看起来像这样:

get '/:action', :controller => 'pages', :as => 'page'

Which would afford you routes like "example.com/hello_world" that would route to PagesController#hello_world, rendering "app/views/pages/hello_world.html". If you want to use ERb, you can add that ".erb" suffix to your view file and then you can use the page_path helper to assemble links:

哪个路由会像“example.com/hello_world”那样路由到PagesController#hello_world,渲染“app / views / pages / hello_world.html”。如果要使用ERb,可以将“.erb”后缀添加到视图文件中,然后可以使用page_path帮助程序来组合链接:

<%= link_to 'Hello World Demo', page_path('hello_world') %>

You will still probably want to extract the common elements into a layout at app/views/layouts/application.html.erb (again, the ERb being optional).

您仍然可能希望将公共元素提取到app / views / layouts / application.html.erb中的布局(同样,ERb是可选的)。


Another route would be to actually separate your application into resources. If you have a page that lists books, for example, you could create a BooksController and put the relevant view under app/views/books/index.html. This doesn't make sense to do if you're not going to provide some additional functionality in the future, though.

另一种方法是将您的应用程序实际分离为资源。例如,如果您有一个列出书籍的页面,您可以创建一个BooksController并将相关视图放在app / views / books / index.html下。但是,如果你将来不打算提供一些额外的功能,这没有任何意义。