Topic: Dynamically generated fields in rails

Hey, I'm trying to accomplish this:

http://i1107.photobucket.com/albums/h390/catscathe/dynamicallygeneratedfields.png

So when you click More, it will dynamically add as new field under 'content' and allow you to save information there.  What's the best practice for this?

I'm in the middle of writing view code that looks like this

 <p><%= @news_blast.content %></p>
        <% if @news_blast.content1 != "" %>
          <br/>
          <p><%= @news_blast.content1 %></p>
        <% end %>

        <% if @news_blast.content2 != "" %>
          <br/>
          <p><%= @news_blast.content2 %></p>
        <% end %>
        <% if @news_blast.content3 != "" %>
          <br/>
          <p><%= @news_blast.content3 %></p>
        <% end %>
        <% if @news_blast.content4 != "" %>
          <br/>
          <p><%= @news_blast.content4 %></p>
        <% end %>
        <% if @news_blast.content5 != "" %>
          <br/>
          <p><%= @news_blast.content5 %></p>
        <% end %>

and just hacking through it on my own.

Last edited by nsj (2011-12-06 13:03:07)

Re: Dynamically generated fields in rails

You should use some javascript technics to add a field, something like that was used for nested forms at http://railscasts.com/episodes/196-nest … orm-part-1

Re: Dynamically generated fields in rails

Thanks, that link is just what I needed!