简体   繁体   English

Ruby-on-rails试图在同一行屏幕上获取文本和link_to

[英]Ruby-on-rails trying to get text and link_to on the same screen line

Ruby on rails - trying to change how a page (view) displays. Ruby on Rails-尝试更改页面(视图)的显示方式。

I am currently using float to display an index page with some text as well as an image. 我目前正在使用float来显示带有一些文本和图像的索引页。
I wish to have the text (markdown post.body) see below end with ... followed by "more" (where more is an underlined link). 我希望文本(markdown post.body)在下面以...结尾,后跟“更多”(其中更多是带下划线的链接)。 Currently "more" appears on a new line. 当前,“更多”出现在新行上。

that is I get ... "the compiled JavaScript code. The second command is "Run", which compiles the code in your editor and evaluates the JavaScript and shows you the result of ... 那就是我得到的“已编译的JavaScript代码。第二个命令是“运行”,它将在您的编辑器中编译代码并评估JavaScript并向您显示...的结果。

more" 更多”

what I want is ... "the compiled JavaScript code. The second command is "Run", which compiles the code in your editor and evaluates the JavaScript and shows you the result of ...more" 我想要的是...“已编译的JavaScript代码。第二个命令是“运行”,它将在您的编辑器中编译该代码并评估JavaScript,并向您显示... more的结果。

I have pasted in relevent part of view below app/views/posts/index 我已经在app / views / posts / index下面的视图的相关部分粘贴了

<div class= "article-face-img"> 
  <%  face_image = article_face_image post %>
  <%= image = image_tag face_image, size: "260x205", class: "article-face-img" %>
  <h1><%= post.title  %>  </h1>
  <%= dateconvert post.updated_at %>
  <%= markdown post.body[0..1250] + "..." %>
  <%= link_to 'more', post %>  
</div>

where "article_face_image" and "markdown" are helper methods. 其中“ article_face_image”和“ markdown”是辅助方法。

from the css 从CSS

// for posts to align image and text  
.article-face-img{
  float: left;
  padding: .8em;
}
.clearfix {
    clear: both;
}

I have tried a number of things including trying to add the post_body to the link before display eg 我尝试了很多事情,包括尝试在显示之前将post_body添加到链接中,例如

<% a = markdown post.body[0..1250] + "..."%>
<% b = link_to 'more', post %>
<%= a = a + b %>

any help appreciated thanks Pierre 任何帮助感谢皮埃尔

I think your problem is that the markdown embeds your text within a <p>...<p/> tag, and this is why your more appears on a separate line from the markdown code. 我认为您的问题是markdown将您的文本嵌入<p>...<p/>标记中,这就是为什么您的more文本与markdown代码分开显示的原因。

I would work this around with: 我将解决此问题:

<%= markdown post.body[0..1250] + "... #{link_to 'more', post}" %>

basically embedding the link within your marked down string. 基本上将链接嵌入标记的字符串中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM