Home Ask Login Register

Developers Planet

Your answer is one click away!

Vaishali Rajput February 2016

How to convert html pages into erb in Rails?

I have been given the task to convert some static html pages into erb pages, to be used in a Rails project. Since all pages belong to same project, they are having a common "application.html.erb" file. But all Html pages have different class names for <body> tag. and since we have common "application.html.erb" file. How to convert such Html pages with different names for <body> tag , into .erb files?


Andrey Konoplenko February 2016

You can use curren_page? helper method that gives you understanding where you are.

Using this method you can create your own helper that adds class method to your body in application layout.

Max Williams February 2016

I would do this with an instance variable, which is expected to be set in the controller.

<body class="<%= @body_class %>">

You can then set this on a per-controller or per-action basis. If there is a "formula" to decide what it is, based on the controller and action, you could do it via a single before_filter defined in ApplicationController.

Post Status

Asked in February 2016
Viewed 2,732 times
Voted 7
Answered 2 times


Leave an answer

Quote of the day: live life