Question

Ruby on rails - trying to change how a page (view) displays.

I am currently using float to display an index page with some text as well as an image.
I wish to have the text (markdown post.body) see below end with ... followed by "more" (where more is an underlined link). 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 ...

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"

I have pasted in relevent part of view below 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.

from the 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 e.g.

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

any help appreciated thanks Pierre

Was it helpful?

Solution

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.

I would work this around with:

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

basically embedding the link within your marked down string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top