Nei*_*eil 0 html ruby-on-rails
我有一个网络应用程序,允许他们在列表表单中添加网站URL,例如www.google.com,所以在显示页面上任何人都可以点击这个并访问网页www.google.com
尝试了一些事情link_to等,但似乎无法让它正常工作
listings.form
<div class="form-group">
<%= f.label "Tell Us About Your Business 25-30 chars max" %>
<%= f.text_area :about, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label "Company Website" %>
<%= f.text_field :url , class: "form-control", placeholder: "E.g www.google.com" %>
</div>
Run Code Online (Sandbox Code Playgroud)
show.html.erb
<div class="blog-header">
<h1 class="blog-title"><%= @listing.job %></h1>
<p class="lead blog-description"><b>Posted on</b> <%= @listing.created_at.strftime("%B %-d, %Y") %></p>
<h4><%= @listing.company %></h4>
<h4><%= @listing.location %></h4>
***<h4><%= link_to @listing.url %></h4>***
</div>
Run Code Online (Sandbox Code Playgroud)
所以目前它创建了一个链接,但没有进入网页.
更新的代码
<div class="blog-header">
<h1 class="blog-title"><%= @listing.job %></h1>
<p class="lead blog-description"><b>Posted on</b> <%= @listing.created_at.strftime("%B %-d, %Y") %></p>
<h4><%= @listing.company %></h4>
<h4><%= @listing.location %></h4>
<h4><%= link_to @listing.url, @listing.url %></h4>
</div>
Run Code Online (Sandbox Code Playgroud)
你需要传递两个参数 link_to
<%= link_to @listing.url, @listing.url %>
Run Code Online (Sandbox Code Playgroud)
第一个参数是要显示的链接的名称,如果没有设置第二个参数,则rails将链接到当前页面
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |