【问题标题】:Hiding html elements隐藏html元素
【发布时间】:2011-12-04 02:47:24
【问题描述】:

我试图隐藏视图中编辑和销毁操作的链接,除非用户使用 http 基本身份验证登录。我在下面附上了我的文件。谢谢

查看https://gist.github.com/1272716 控制器https://gist.github.com/1272712

【问题讨论】:

    标签: html ruby-on-rails ruby ruby-on-rails-3 model-view-controller


    【解决方案1】:

    您需要保存/存储身份验证结果,然后在您的视图中进行条件渲染。

    控制器

    protected
    
    def authenticate
      @authenticated = authenticate_or_request_with_http_basic do |user, password|
        user == "x4556d4s" && password == "fd55sas64x"
      end 
    end 
    

    查看

    <%= link_to "New Link", :controller => :links, :action => :new %>
    <table>
    <% @links.each do |link| %>
      <tr>
        <td> <%= link_to '+', up_link_url(link), :method => :put %> <%= link.points %> <%= link_to '-', down_link_url(link), :method => :put %> </td>
        <td> <a href=  "<%= link.url %>"> <%= link.title %></a> </td>
    
        <% if @authenticated %>
          <td><%= link_to 'Destroy', link, :confirm => 'Are you sure?', :method => :delete %></td>
          <td><%= link_to 'Edit', edit_link_path(link) %></td>
        <% end %>
    
      </tr>
    <% end %>
    </table>
    

    【讨论】:

      猜你喜欢
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多