我剛接觸rails並遵循Micheal Hartl的教程。在他的教程中,他使用'form_for'標籤在他的應用中創建表單。但是,我喜歡css框架,因此決定使用Zurb Foundation來手動創建HTML表單。表單是在模式內部創建的。這裏是表單代碼:爲什麼我的ruby on rails應用程序不在我的部分html頁面中渲染rails代碼?
<div class="reveal" id="StudentLoginModal" data-reveal
data-animation-in="hinge-in-from-top" data-animation-out="hinge-out-from-bottom">
<form data-abide novalidate action="/login" method="POST">
<%= form_authenticity_token %>
<div data-abide-error class="alert callout" style="display: none;">
<p><i class="fi-alert"></i> There are some errors in your form.</p>
</div>
<div class="row">
<label style="font-family: sans-serif;
font-size: 1.15em;
font-weight: bold;">UserName
<input name="session[name]" type="text" placeholder="Your Exam Roll.no" required pattern="number"
aria-describedby= "exampleHelpText">
<span class="form-error">
Yo, you had better fill this out, it's required.
</span>
<p class="help-text" id="exampleHelpText">Enter your username.</p>
</label>
<label style="font-family: sans-serif;
font-size: 1.15em;
font-weight: bold;">Password
<input type="password" name="session[password]" id="password" placeholder="yeti4preZ" aria-describedby= "exampleHelpText1" required >
<span class="form-error">
I'm required!
</span>
<p class="help-text" id="exampleHelpText1">Enter a password please.</p>
</label>
<input type="submit" class="button" value="Submit">
</div>
</form>
<button class="close-button" data-close aria-label="Close reveal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
但問題是,Rails已經CSRF保護,它不會允許用戶提交表單沒有真實性令牌。我試圖使用<%= form_authenticity_token%>檢索值,但它沒有向窗體添加任何值。但是,該標籤顯示其他頁面中令牌的值。有任何想法嗎?
謝謝:)
編輯1:我認爲這個問題是我使用的渲染登錄表單的模式。
你可以把'skip_before_filter:verify_authenticity_token'在你的控制器。 –
但是,這將關閉CSRF。這不是建議嗎? – Prajjwal