如果当前页面posts_edit_path然后显示文本

时间:2013-02-21 15:27:42

标签: ruby-on-rails ruby

我只有在用户位于posts_edit_path时才需要显示文字,我该怎么做?

谢谢!

我的帖子表示我要向posts_edit_path

中的用户显示此文本(Laizzzēstubildes,ieklikšķiniettāsunpublicējietrakstu。)
<%= 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 %>

2 个答案:

答案 0 :(得分:2)

CURRENT_PAGE?应该帮助你做你想做的事情。例如:

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

点击此链接了解详情:ruby on rails api: current_page?

答案 1 :(得分: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 %>