如何使用simple_format和auto_link在新标签中打开链接?

时间:2016-05-17 00:33:10

标签: ruby-on-rails ruby-on-rails-4

我的网络应用程序中有以下行。

IsAuthenticated

我尝试添加目标以在新标签中打开链接,但它不起作用。

[Test]
public void Should_GetUserId_From_Identity() {
    //Arrange
    var username = "test@test.com";
    var identity = new GenericIdentity(username, "");
    var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username);
    identity.AddClaim(nameIdentifierClaim);

    var mockPrincipal = new Mock<IPrincipal>();
    mockPrincipal.Setup(x => x.Identity).Returns(identity);
    mockPrincipal.Setup(x => x.IsInRole(It.IsAny<string>())).Returns(true);

    Kernel.Rebind<IPrincipal>().ToConstant(mockPrincipal.Object);

    //Act
    var principal = Kernel.Get<IPrincipal>();

    //Asserts        
    Assert.AreEqual(username, principal.Identity.GetUserId());
    Assert.IsTrue(principal.Identity.IsAuthenticated);
}

我如何让这个工作?感谢。

2 个答案:

答案 0 :(得分:2)

尝试使用auto_link助手,如下所示:

year = data(:,1); %Year (2010, 2011...2016)
month = data(:,2); %Month (1,2,3,etc.)
mt = data(:,3); %NYSE Annualized Monthly Turnover
at = data(:,4); %NYSE Annualized Year to Date Turnover

z = 1:76;

a = plot(z, mt, 'r-', z, at, 'b-');
hold on
legend(a, 'Annualized Monthly Turnover NYSE', 'Annualized Year NYSE')
title('Annualized Monthly & Year-to-Date Turnover of NYSE Securities')
xlabel('Date')
ylabel('Turnover (x100%)')
hold off

答案 1 :(得分:1)

我建议像这样反转simple_format和auto_link:

<%= auto_link(simple_format(@micropost.content), html: { target: '_blank' }) %>

这样您就不必将清理设置为假