回答

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>