M
M
Maxim2015-02-17 18:49:34
Ruby on Rails
Maxim, 2015-02-17 18:49:34

Rails 4.2, ActiveRecord.all, how not to return last element?

class QuestionsController < ApplicationController
  def index
  	@questions = Question.all
  	@questions.order(:created_at)
  end

<%= @questions.each do | question | %>
  <%= question.title %><br>
  <%= question.text %><br>
 <% end %>
  <%= link_to "New", new_question_path %>

As a result, the entire array appears at the end, that is, in addition to the elements, the entire array of records appears.
hello
world
azaza
lalka
[#<Question id: 1, title: "hello ", text: "world", created_at: "2015-02-17 15:28:18", updated_at: "2015-02-17 15:28:18">, #<Question id: 2, title: "azaza", text: "lalka\r\n", created_at: "2015-02-17 15:33:25", updated_at: "2015-02-17 15:33:25">] New

How not to bring it out?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-02-17
@1kachan

<%= @questions.each do | question | %>
Replace with
Equals means that "you need to output the result of this command to the template engine"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question