Question

I am looking for the possibility to build a table in my view dynamically, depending on selection.

Currently i have 2 combox ,2 submit buttons and a text_area in my view eg.:

  <%= select_tag :user_selected, options_from_collection_for_select(@user, 'id', 'lastname') %>
  <%= select_tag(:rights_id, options_for_select([['Read', 1], ['Read/Write', 2], ['Read/Write/Delete', 3]])) %>
  <%= submit_tag "add" %>

  <%= fields_for :content do |tf| %>
    <%= tf.text_area  :text , :id => 'text',  :cols => '100', :rows => '25' %>
  <% end %>

  <%= tf.submit 'Save' %>

Every time if i hit the add button, i will expand the table with my selection, but the content from the text_area shoud be unchanged.

Is this possible in rails? If yes, how can i do it?

Was it helpful?

Solution

You can use a remote form + partials, and js.rjs file will refresh the table in main window.

It seems it looks like this getting started example mixed with this ajax mini-tutorial example, both from Rails Guides.

note this, from Working with javascript:

<b>Users</b>

<ul id="users">
<% @users.each do |user| %>
  <%= render user %>
<% end %>
</ul>

<br>

<%= form_for(@user, remote: true) do |f| %>
  <%= f.label :name %><br>
  <%= f.text_field :name %>
  <%= f.submit %>
<% end %>

OTHER TIPS

You have to use Javascript or Javascripts frameworks like jquery. You have to write the event on add button in javascript(or jquery)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top