简体   繁体   中英

Ruby Rails is it possible to check before displaying form?

Is it possible to check submission before showing this simple form:

<%= form_for @article, url: {action: "create"}, html: {class: "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, size: "60x12" %>
  <%= f.submit "Create" %>
<% end %>

like if its already submitted first time show other html content instead ?

Test the object. If you're using ActiveRecord/Mongoid:

<% if @article.new_record? %>
  ... display form ...
<% else %>
  ... do something different ...
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM