How can I change the number of items that end up in a list

pixelfairy

I'm hacking away at a rails project and I wanted to modify the number of items that end up on a particular page. The page gets populated via an array of items.

For the life of me I can't figure out how to make it show only 2 instead of 4 items.

In the haml file there is this section:

%ul.story-list
- @stories.each do |story|
  %li
    - unless story.image.blank?
      .img-container{ class: ((story.video.blank?)? "": "video-container") }
        = image_tag(story.image_url, alt: story.name, class: ((story.video.blank?)? "": "js-has-video"), :video => story.video)
    .story-data
      %h4= story.name
      %h5.location= story.location
      %p.quote= story.story
      - if story.get_connected?
        = link_to 'Get Connected', connect_path
      - elsif story.gather_supplies?
        = link_to 'Gather Supplies', supplies_path
      - elsif story.make_a_plan?
        = link_to 'Make a plan', plan_path

The page shows up (on the server) with four story items, I want it to only show two. I was expecting to open the haml file and just delete some lines (or comment them out). I'm so confused.

So, I suspect the number of stories comes from a controller or something like that. ..but maybe it is coming from the placeholder data on the server?

あなたが私を助けてくれるように促された場合、すべてのコードはここにありますhttps://github.com/city72/city-72

私が変更しようとしている正確なページはこれです。2つのストーリーだけを含めたいです:http//collier72.herokuapp.com/stories

奇妙なことに、私のローカル環境では、ストーリーをまったく編集できません。それが、アイテムの数がデータから来ていることを私に教えてくれます。

ストーリーコントローラーは、ストーリーの数を指定しないこの小さなファイルです。

class StoriesController < ApplicationController

  after_filter :static_content

  def index
    all_stories = EmergencyStory.order("index,id ASC").all
    @selected_story = all_stories.select {|s| s.selected}.first
    @stories = all_stories.collect.select {|s| !s.selected}
  end

end
フィリップ・ホールストロム

このファイルを開きます。

https://github.com/city72/city-72/blob/master/app/controllers/stories_controller.rb#L8

これからその行を変更します:

@stories = all_stories.collect.select {|s| !s.selected}

これに:

@stories = all_stories.collect.select{|s| !s.selected}.slice(0,2)

私の知る限り、4が返されるという事実は意図的なものではなく、データベースにあるものにすぎません。slice(0,2)最初の2つの項目を返します。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how can I assert that a number goes or a list grows up in TLA+?

分類Dev

How can I round up the number of periodic digits?

分類Dev

How can I create a map with every two items in a list in Kotlin?

分類Dev

How can i create a list (new) from an existing list where items of list(new) will be list in python

分類Dev

How can I list up orphan packages in composer

分類Dev

How can I change my number validation from a form to a prompt?

分類Dev

How can I repeat a list a variable number of times

分類Dev

How can I change the value of an element in a list which belongs to a dictionary?

分類Dev

android:- How to change the language of list items of recyclerview?

分類Dev

How to change items in a tuple without casting to a list?

分類Dev

How can I know the total number of chunks/items to be processed at the beginning of a Spring Batch Step?

分類Dev

Returning the number of items in a list

分類Dev

How can I change text animations so that they just show up in their own space?

分類Dev

How can I draw a List and all it's items in Inspector editor script?

分類Dev

How I can remove more than 1 items from drop down list?

分類Dev

Can I display multiselect list items as onordered list using Razor?

分類Dev

(Python) How can I let a user open a text file and then change an integer / number

分類Dev

How can i remove a particular comma at end

分類Dev

How can I apply padding to the end of a line?

分類Dev

How can I 'clean up' a virtualenv?

分類Dev

How can I get the number of columns and rows from 2D list

分類Dev

How can I make python's argparse accept any number of [-R a b]s, and aggregate them into a list

分類Dev

How can I change the column names of a list to the first row of each data frame in a loop?

分類Dev

How do I read arbitrary big number at the end of textView?

分類Dev

How to "number" array items?

分類Dev

how can i loop for store items i want in ExtJS XTemplate?

分類Dev

Different number of processors end up with different results?

分類Dev

How can I get the number of enums as a constant?

分類Dev

how can i combine href with id number

Related 関連記事

  1. 1

    how can I assert that a number goes or a list grows up in TLA+?

  2. 2

    How can I round up the number of periodic digits?

  3. 3

    How can I create a map with every two items in a list in Kotlin?

  4. 4

    How can i create a list (new) from an existing list where items of list(new) will be list in python

  5. 5

    How can I list up orphan packages in composer

  6. 6

    How can I change my number validation from a form to a prompt?

  7. 7

    How can I repeat a list a variable number of times

  8. 8

    How can I change the value of an element in a list which belongs to a dictionary?

  9. 9

    android:- How to change the language of list items of recyclerview?

  10. 10

    How to change items in a tuple without casting to a list?

  11. 11

    How can I know the total number of chunks/items to be processed at the beginning of a Spring Batch Step?

  12. 12

    Returning the number of items in a list

  13. 13

    How can I change text animations so that they just show up in their own space?

  14. 14

    How can I draw a List and all it's items in Inspector editor script?

  15. 15

    How I can remove more than 1 items from drop down list?

  16. 16

    Can I display multiselect list items as onordered list using Razor?

  17. 17

    (Python) How can I let a user open a text file and then change an integer / number

  18. 18

    How can i remove a particular comma at end

  19. 19

    How can I apply padding to the end of a line?

  20. 20

    How can I 'clean up' a virtualenv?

  21. 21

    How can I get the number of columns and rows from 2D list

  22. 22

    How can I make python's argparse accept any number of [-R a b]s, and aggregate them into a list

  23. 23

    How can I change the column names of a list to the first row of each data frame in a loop?

  24. 24

    How do I read arbitrary big number at the end of textView?

  25. 25

    How to "number" array items?

  26. 26

    how can i loop for store items i want in ExtJS XTemplate?

  27. 27

    Different number of processors end up with different results?

  28. 28

    How can I get the number of enums as a constant?

  29. 29

    how can i combine href with id number

ホットタグ

アーカイブ