Opening .html.erb files in browser

2019-09-06 17:52发布

问题:

Is there a way to open .html.erb files by themselves in the browser. The Rails app I am trying to have a look at is in rails 2.3 and will not run locally on the rails server nor will it run when I give the command script/server.

I would just like to open the individual views in the browser by themselves...is this possible?

回答1:

You can open them in the browser, but the <% %> and <%= %> tags will get shown as-is instead of executing the Ruby code. These are template files that need to get processed by Rails to fill in data at runtime. Your best bet is TsaiKoga's answer, making a controller action render the template in question.



回答2:

In rails4 you can do it like this:

erb a.html.erb > a.html

Maybe it doesn't work in rails 2.3. If you want to render that view, maybe you can use an action just like users#index and change the code to render it:

render "devise/mailer/a.html.erb", :layout => false