2015-08-06 7 views
0

У меня есть создать приложение рельсы с Mongoid, но им сталкивается с одной проблемой в ДАТАДата не работает в рельсах приложение с Монго идентификатором

Я создал леску с именем «проводки»

Когда им дата редактирования будет обновлена ​​....

Я следовать указаниям Railscast # 238 Mongoid here

есть мой файл posting.rb

class Posting 
    include Mongoid::Document 
    field :title 
    field :description 
    field :comments 
    field :published, :type => Date 
end 

это мой _from.html.erb

<%= form_for(@posting) do |f| %> 
    <% if @posting.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@posting.errors.count, "error") %> prohibited this posting from being saved:</h2> 

     <ul> 
     <% @posting.errors.full_messages.each do |message| %> 
     <li><%= message %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :title %><br> 
    <%= f.text_field :title %> 
    </div> 
    <div class="field"> 
    <%= f.label :description %><br> 
    <%= f.text_field :description %> 
    </div> 
    <div class="field"> 
    <%= f.label :published %><br> 
    <%= f.date_select :published %> 
    </div> 
    <div class="field"> 
    <%= f.label :comments %><br> 
    <%= f.text_area :comments %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

и, наконец, мой show.html.erb файл

<p id="notice"><%= notice %></p> 

<p> 
    <strong>Title:</strong> 
    <%= @posting.title %> 
</p> 

<p> 
    <strong>Description:</strong> 
    <%= @posting.description %> 
</p> 
<p> 
    <strong>published:</strong> 
    <%= @posting.published %> 
</p> 

<p> 
    <strong>Comments:</strong> 
    <%= @posting.comments %> 
</p> 

<%= link_to 'Edit', edit_posting_path(@posting) %> | 
<%= link_to 'Back', postings_path %> 

ответ

0

Что вы имеете в виду, не за работой? не похоже, что вы использовали опубликованное свойство в любом из ваших представлений.

в вашем show.html.erb вы используете

<%= f.date_select :pub %> 

и в вашем show.html.erb вы используете

<%= @posting.pub %> 

Однако нет никакой собственности называется pub в вашей Posting модели. Что там у вас называется published

field :published, :type => Date

Вы либо должны переименовать его в модели, или во взглядах на матч.

+0

thx для воспроизведения @shaunak. Я изменил этот файл «show.html.erb», даже если у меня есть проблема, «DATE» не отображается на странице просмотра (в браузере) и даже не хранится в базе данных ..............! может у меня помочь мне из этого ...... – Nani