How to make the index view retrieve/output data in the order submitted in the posting form?
<p>Using a nested form, I create a post which is ordered <code>Text1</code>, <code>Url1</code>, <code>Text2</code>.</p>

<p>However, when I retrieve this data (controller Index action) and display it in the view (<code>index.html.erb</code>) it displays as <code>Text1</code>, <code>Text2</code>, <code>Url1</code>. How can I get it to display in the view with the original order I gave it in the nested posting form? </p>

<p>Your help would be amazing - I just can't make this work!</p>

<p>Nested Form:
<a href="https://i.stack.imgur.com/AQe36.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AQe36.png" alt="Nested Form http://imgur.com/b7lSbSt"></a></p>

<p>Browser:
<a href="https://i.stack.imgur.com/0m5Ji.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0m5Ji.png" alt="enter image description here"></a></p>

<p>Post Model</p>

<pre><code>  class Post &lt; ActiveRecord::Base
   has_many :texts
   has_many :urls 
   accepts_nested_attributes_for :texts, :urls
  end
</code></pre>

<p>Text Model</p>

<pre><code>  class Text &lt; ActiveRecord::Base
   belongs_to :post 
  end
</code></pre>

<p>Url Model</p>

<pre><code>  class Url &lt; ActiveRecord::Base
   belongs_to :post
  end
</code></pre>

<p>Schema</p>

<pre><code> create_table "posts", force: :cascade do |t|
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
 end

 create_table "texts", force: :cascade do |t|
   t.text     "textattr"
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
   t.integer  "post_id"
 end

 add_index "texts", ["post_id"], name: "index_texts_on_post_id"

 create_table "urls", force: :cascade do |t|
   t.string   "urlattr"
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
   t.integer  "post_id"
 end

 add_index "urls", ["post_id"], name: "index_urls_on_post_id"
</code></pre>

<p>Posts Controller</p>

<pre><code> class PostsController &lt; ApplicationController

  def index
    @posts = Post.includes(:texts, :urls).all.order(created_at: :desc)
  end

  def show
   @post = Post.find(params[:id])
   @texts = @post.texts 
   @urls = @post.urls 
   @photos = @post.photos 
  end 

  def new
    @post = Post.new 
  end 

  def create
   @post = Post.new(post_params) 
    if @post.save 
     redirect_to @post
    else 
     render 'new'
    end 
  end


   private 
    def post_params 
        params.require(:post).permit(:texts_attributes =&gt; [:textattr], :urls_attributes =&gt; [:urlattr], :photos_attributes =&gt; [:image])
     end 
 end
</code></pre>

<p>View (Index.html.erb) </p>

<pre><code>&lt;% @posts.each do |post| %&gt; 

 &lt;% post.texts.each do |text|%&gt;
  &lt;%= text.textattr %&gt; &lt;br&gt; 
 &lt;% end %&gt;

 &lt;% post.urls.each do |url|%&gt;
  &lt;%= url.urlattr %&gt; &lt;br&gt; 
 &lt;% end %&gt; 

&lt;% end %&gt; 
</code></pre>