2016-05-01 137 views
0

我知道這已被回答,但我已經通讀了其中大部分,我仍然無法弄清楚。有人知道發生了什麼嗎?語法錯誤,意外的keyword_else,期待輸入結束其他^

<% if current_user.try(:email) == Join.all(:email) %> 
     <div class="panel-default"> 
     <div class="panel-body"> 
      You're already signed up for this month! Thanks! 
     </div> 
     </div> 
    <% else %> 
     <% if user_signed_in? %> 
     <%= form_for @join do |f| %> 
      <%= f.email_field :email, value: current_user.email, class: "form-control input-lg", id: "join" %> <br> 
      <%= f.submit "Join This Month's Rewards", class: "btn btn-success btn-lg" %> 
     <% end %> 
     <% end %> 
    <% else %> 
     <div class="panel panel-default"> 
     <div class="panel-body"> 
     Sorry, you're not currently signed in, so you can't sign up for our rewards. You can sign in <a href="https://stackoverflow.com/users/sign_in">here.</a> 
     </div> 
     </div> 
    <% end %> 

以下是完整的錯誤:/Users/Sam/Documents/workspace/rewardsApp/app/views/joins/new.html.erb:19: syntax error, unexpected keyword_else, expecting keyword_end else ^的錯誤是在第29行,這是後<% else %>兩個<% end %> 幫助最感謝!

+0

您應該提供完整的錯誤。 – Laurel

+0

@Laurel我修好了......你知道這個問題是什麼嗎?我討厭尋求幫助,但我很困難。 – GOAT

回答

0

它看起來像您的if/else設置結束爲時過早以說明視圖的三種狀態。

<% if current_user.try(:email) == Join.all(:email) %> 
     <div class="panel-default"> 
     <div class="panel-body"> 
      You're already signed up for this month! Thanks! 
     </div> 
     </div> 
    <% else %> 
     <% if user_signed_in? %> 
     <%= form_for @join do |f| %> 
      <%= f.email_field :email, value: current_user.email, class: "form-control input-lg", id: "join" %> <br> 
      <%= f.submit "Join This Month's Rewards", class: "btn btn-success btn-lg" %> 
     <% else %> 
      <div class="panel panel-default"> 
      <div class="panel-body"> 
      Sorry, you're not currently signed in, so you can't sign up for our rewards. You can sign in <a href="https://stackoverflow.com/users/sign_in">here.</a> 
      </div> 
      </div> 
     <% end %> 
    <% end %> 
+0

感謝@joncoud工作。表格後忘記了<% end %>。但除此之外,它的工作。 – GOAT

0

這可能是爲什麼適當縮進代碼非常有用的一個很好的例子。一旦你這樣做,很明顯你有第二個else條款。

<% if current_user.try(:email) == Join.all(:email) %> 
    <div class="panel-default"> 
    <div class="panel-body"> 
     You're already signed up for this month! Thanks! 
    </div> 
    </div> 
<% else %> 
    <% if user_signed_in? %> 
    <%= form_for @join do |f| %> 
     <%= f.email_field :email, value: current_user.email, class: "form-control input-lg", id: "join" %> <br> 
     <%= f.submit "Join This Month's Rewards", class: "btn btn-success btn-lg" %> 
    <% end %> 
    <% end %> 
<% else %> <%# <= Uh oh, second else clause %> 
    <div class="panel panel-default"> 
    <div class="panel-body"> 
     Sorry, you're not currently signed in, so you can't sign up for our rewards. You can sign in <a href="https://stackoverflow.com/users/sign_in">here.</a> 
    </div> 
    </div> 
<% end %> 
相關問題