Opening .html.erb files in browser

早过忘川 提交于 2020-01-07 04:10:54

问题


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


来源:https://stackoverflow.com/questions/20292752/opening-html-erb-files-in-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!