2015-04-02 70 views
0

中斷後,我回到了rails中,ERB沒有按預期呈現。我從一個全新的項目中打開了一個視圖,在Chrome和Firefox中打開了一箇舊項目的視圖。在所有四種排列中都是同樣的問題。在瀏覽器中顯示爲HTML文件的ERb文件

這裏的_form.html.erb

<%= form_for(@cat) do |f| %> 
    <% if @cat.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@cat.errors.count, "error") %> prohibited this cat from being saved:</h2> 

     <ul> 
     <% @cat.errors.full_messages.each do |message| %> 
     <li><%= message %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :birth_date %><br> 
    <%= f.date_select :birth_date %> 
    </div> 
    <div class="field"> 
    <%= f.label :color %><br> 
    <%= f.text_field :color %> 
    </div> 
    <div class="field"> 
    <%= f.label :name %><br> 
    <%= f.text_field :name %> 
    </div> 
    <div class="field"> 
    <%= f.label :sex %><br> 
    <%= f.text_field :sex %> 
    </div> 
    <div class="field"> 
    <%= f.label :description %><br> 
    <%= f.text_area :description %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

而這裏的new.html.erb

<h1>New Cat</h1> 

<%= render 'form' %> 

<%= link_to 'Back', cats_path %> 

這裏就是瀏覽器呈現:

contents of html.erb file, displayed as an html file

我運行軌4.2.1和紅寶石2.2.1,我是兩個版本的全新。

+0

沒有足夠的信息來幫助;相關的項目結構(例如'app' dir),樣本控制器等,也可能是Gemfile。 – 2015-04-03 00:18:34

+0

謝謝,我只是在github上添加了一個應用程序的鏈接;我會確保這個SO帖子反映了問題和解決方案的最終結果。 – rainbowsorbet 2015-04-03 00:30:37

回答

1

事實證明,我以我習慣於HTML文件(Command + O - >選擇文件)的方式在瀏覽器中打開ERb文件。難怪它被認爲是HTML!

對於後代:您必須導航到終端中的應用程序目錄,使用「rails s」啓動rails服務器,並從localhost:3000導航到您的視圖。

0

我想你的views目錄中可能有一個揮之不去的new.html

+0

謝謝你的想法,但我仔細檢查過,事實並非如此。此外,[這篇文章](http://stackoverflow.com/questions/20292752/opening-html-erb-files-in-browser)意味着rails 4不允許你在瀏覽器中打開視圖進行檢查(和這就像我已經得到)。 – rainbowsorbet 2015-04-03 00:10:36

+0

你可以發佈你的代碼到github回購,所以我可以檢討它嗎? – 2015-04-03 00:14:01

+0

解決了這個問題,謝謝你看這個 – rainbowsorbet 2015-04-03 00:44:38

相關問題