[RUBY] [Rails] How to omit the display of the character string of the link_to method


macOS 10.15.5 Rails Docker 19.03.12

How to omit the display of the character string of the link_to method

Please see this image. The text of the post displayed on the post list screen, but since the entire text is also displayed on the list screen as it is, it looks very bad like this. スクリーンショット 2020-10-30 14.55.26.png

Make this refreshing as follows. スクリーンショット 2020-10-30 14.55.51.png

Use truncate method

The code before omitting is as follows.


<%= link_to(post.content, "/posts/#{post.id}") %>

Add the ``` truncate method` `` to this code.


<%= link_to post.content.truncate(40), "/posts/#{post.id}" %>

By rewriting in this way, you can omit the display of the character string of the link_to method! This (40) means how many characters to switch to "..." display ^ _ ^

Recommended Posts

[Rails] How to omit the display of the character string of the link_to method
How to use the link_to method
[Rails] How to display the list of posts by category
[Rails] How to use the map method
I tried to understand how the rails method "link_to" is defined
Output of how to use the slice method
How to display the result of form input
[Rails] How to solve the time lag of created_at after save method
How to remove the underline displayed by Rails link_to
[Rails, JS] How to implement asynchronous display of comments
How to add characters to display when using link_to method
[Rails] How to change the column name of the table
[Java] How to easily get the longest character string of ArrayList using stream
[Rails] How to get the contents of strong parameters
[Rails] How to display an image in the view
[Rails] I want to display the link destination of link_to in a separate tab
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
I want to expand the clickable part of the link_to method
Let's summarize how to extend the expiration date of Rails
[Rails] How to display information stored in the database in view
How to use the include? method
How to use the form_with method
[rails] How to display db information
How to display 0 on the left side of the standard input value
I tried to understand how the rails method "redirect_to" is defined
[Rails] How to change the page title of the browser for each page
How to check for the contents of a java fixed-length string
[Rails 5] How to display the password change screen when using devise
[Swift] Copy the character string to the clipboard
[Java] How to use the toString () method
[Rails] How to display error messages individually
How to determine the number of parallels
How to sort the List of SelectItem
The process of introducing Vuetify to Rails
[Rails] How to use video_tag to display videos
Method definition location Summary of how to check When defined in the project and Rails / Gem
[Rails] How to use helper method, confimartion
[Java beginner] Conversion from character string to numerical value-What is the parseInt method of the Integer class? ~
How to switch the display of the header menu for each transition page
[Java] How to use substring to cut out a part of a character string
[Java] How to get to the front of a specific string using the String class
How to solve the local environment construction of Ruby on Rails (MAC)!
How to display the text entered in text_area in Rails with line breaks
[Ruby On Rails] How to search the contents of params using include?
How to make the schema of the URL generated by Rails URL helper https
[Rails] How to decide the destination by "rails routes"
[Order method] Set the order of data in Rails
How to find the cause of the Ruby error
[Rails] Button to return to the top of the page
[Rails] Introduction of pry-rails ~ How to debug binding.pry
[Ruby on Rails] How to display error messages
Customize how to divide the contents of Recyclerview
[Delete the first letter of the character string] Ruby
How to get today's day of the week
[Ruby] Code to display the day of the week
How to use the replace () method (Java Silver)
How to use JQuery in js.erb of Rails6
[Rails] How to solve "Uglifier :: Error: Unexpected character'`'"
[Ruby on Rails] How to use session method
[Java] How to get the authority of the folder
How to check Rails commands in the terminal