0
我嘗試在視圖中顯示驗證錯誤以創建新文章頁面。我在文章模型中驗證了檢查主體和標題的存在(驗證:title,:body,:presence => true)。它不允許創建新的文章,當我保留文章和標題文本框但顯示「模板不見了」與下面的信息錯誤。「模板丟失」錯誤。缺少模板創建
Missing template articles/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "F:/kuta/billi/app/views" * "C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-bootstrap-rails-2.2.6/app/views" * "C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.2.3/app/views"
我已經把<%= f.error_messages%>中部分爲文章的新的一頁,並把寶石 'dynamic_form' 中的Gemfile。
_form.html.erb的文/ new.html.erb
<%= form_for @article, :html => { :class => '' } do |f| %>
<%= f.error_messages %>
<div>
<%= f.label :title, :style => "margin-top:10px;" %>
<div>
<%= f.text_field :title, :style => "width:730px; height:30px; border: 1px solid #66c9ee;margin-top:10px; background-color:#FFFFFF;" %>
</div>
</div>
<div>
<%= f.label :body, :class => 'control-label' %>
<%= f.text_area :body, :style => "width:730px; height:250px; border: 1px solid #66c9ee;margin-top:10px; background-color:#FFFFFF;" %>
<%= f.label :tag_list, :style => "margin-top:10px" %><br />
<%= f.text_field :tag_list, :style => "width:730px; height:30px; border: 1px solid #66c9ee;margin-top:0px; background-color:#FFFFFF;" %>
<div style="margin-top: 20px">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
articles_path, :class => 'btn' %>
</div>
<% end %>
article.rb模型
class Article < ActiveRecord::Base
attr_accessible :title, :body
attr_accessible :tag_list
has_many :comments
belongs_to :user
has_many :taggings
has_many :tags, through: :taggings
validates :title, :body, :presence => true
def tag_list
self.tags.collect do |tag|
tag.name
end.join(", ")
end
def tag_list=(tags_string)
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq
new_or_found_tags = tag_names.collect { |name| Tag.find_or_create_by_name(name) }
self.tags = new_or_found_tags
end
end
能否請你幫我,我哪裏錯了。
喜zippie呈現新的模板,你的建議爲我工作。謝謝。但驗證錯誤顯示沒有任何顏色(基本上它應該是紅色的)。任何想法如何獲得他們的顏色。謝謝。 –
當它們顯示時,右鍵單擊 - >檢查元素並查看包裹它們的div具有哪個類或ID。一旦你發現讓他們與CSS紅色 – Zippie