开发者

Checking data in the form not be empty

开发者 https://www.devze.com 2023-03-21 22:27 出处:网络
in the view (form) I check the data to be not blank (empty in php:)) but what I am doing is ugly: <% if request.post? %>

in the view (form) I check the data to be not blank (empty in php:)) but what I am doing is ugly:

<% if request.post? %>
<% if @ticket[:name].blank? %>
<% style="fieldWithErrors" %>
<% else %>
<% style="field" %>
<% end %>
<% if @ticket[:department_id].blank? %>
<% style1="fieldWithErrors" %>
<% else %>
<% style1="field" %>
<% end %>
<% else %>
<% style=" " %>
<% style1=" " %>
<% end %>

as default the style of inputs must be "" if the data are submitted there are开发者_如何学Python checked not be blank, all these spoil the form, so where its should be placed in a project and how its do in the correct way?


Put your verification stuff in your model. Check this out: http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/ it has everything you need

0

精彩评论

暂无评论...
验证码 换一张
取 消