-2

只有当用户在posts_edit_path中时我才需要显示文本,我该怎么做?

谢谢!

我的帖子形成了我想向 post_edit_path 中的用户显示此文本的位置

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

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

  <div id="field">
    <%= f.label :Nosaukums %>:<br /><br />
    <%= f.text_field :title %><br /><br />
  </div>
  <div id="field">
    <%= f.label :Raksts %>:<br /><br />
    <%= f.text_area :content %><br /><br />
  </div>
  <div id="field_browse">
    <b><%= f.label :Bildes %>:</b><br />
        Lai izdzēstu bildes, ieklikšķiniet tās un publicējiet rakstu.<br /><br />
    <%= f.fields_for :assets do |asset| %>
        <% if asset.object.new_record? %>
        <div style="clear: both;"></div>
            <%= asset.file_field :image %>          
            <%= f.link_to_remove "Noņemt" %>
        <% end %>   
        <% unless asset.object.new_record? %>
        <p>
            <div id="pictures_in_form"><%= link_to image_tag(asset.object.image.url(:thumb)), asset.object.image.url(:big), :class => "fancybox", :rel => "gallery" if asset.object.image? %></div>                         
            <div id="delete_box"><%= asset.check_box :_destroy if asset.object.image?%></div>
        </p>
        <% end %>
    <% end %>
  <%= f.link_to_add "Pievienot bildes", :assets %>
  </div>
  <div style="margin-top: 15px;">
    <%= f.submit "Publicēt rakstu", :id => "button-link" %>
  </div>
<% end %>
4

2 回答 2

2

当前页面?应该帮助你做你所追求的。例如:

if current_page?(:controller => "post", :action => "edit")

查看此链接了解更多信息:ruby on rails api: current_page?

于 2013-02-21T15:44:10.623 回答
1

你可以这样做:

 <div id="field_browse">
<b><%= f.label :Bildes %>:</b><br />
<%=  "Lai izdzēstu bildes, ieklikšķiniet tās un publicējiet rakstu." if action_name.eql? "edit" %>
   <br /><br />
<%= f.fields_for :assets do |asset| %>
    <% if asset.object.new_record? %>
    <div style="clear: both;"></div>
        <%= asset.file_field :image %>          
        <%= f.link_to_remove "Noņemt" %>
    <% end %>   
    <% unless asset.object.new_record? %>
    <p>
        <div id="pictures_in_form"><%= link_to image_tag(asset.object.image.url(:thumb)), asset.object.image.url(:big), :class => "fancybox", :rel => "gallery" if asset.object.image? %></div>                         
        <div id="delete_box"><%= asset.check_box :_destroy if asset.object.image?%></div>
    </p>
    <% end %>
<% end %>
<%= f.link_to_add "Pievienot bildes", :assets %>

于 2013-02-21T15:49:43.050 回答