隐藏html元素

隐藏html元素,html,ruby-on-rails,ruby,ruby-on-rails-3,model-view-controller,Html,Ruby On Rails,Ruby,Ruby On Rails 3,Model View Controller,我试图在视图中隐藏编辑和销毁操作的链接,除非用户已使用http basic auth登录。我在下面附上了我的文件。谢谢 看法 控制器您需要保存/存储身份验证结果,然后在视图中有条件地呈现 控制器: protected def authenticate @authenticated = authenticate_or_request_with_http_basic do |user, password| user == "x4556d4s" && password =

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

看法
控制器

您需要保存/存储身份验证结果,然后在视图中有条件地呈现

控制器

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>
查看

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>
:链接,:操作=>:新建%>
:put%>:put%>
“你确定吗?”,:method=>:delete%>