From 17755b3c36b93410fcb10a5b9464d886da2d8099 Mon Sep 17 00:00:00 2001 From: Tomer Kimia Date: Tue, 4 Mar 2014 20:38:23 -0500 Subject: dynamic formgit add app/views/tournaments/new.html.erb app/views/tournaments/_selected.html.erb --- app/views/tournaments/_selected.html.erb | 30 ++++++++++++++++++++++++++++-- app/views/tournaments/new.html.erb | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'app/views/tournaments') diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index 3b14404..4277d8e 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -1,5 +1,31 @@ +<%= form_for(@tournament) do |f| %> + <% if @tournament.errors.any? %> +
+

<%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:

- <%= content_tag(:p, "Hello World") %> + +
+ <% end %> + <%# this is the dynamic script to output fields to the form %> + <% @chosen = Game.find(@game) %> + <% @chosen.attributes.each do |name, value| %> + <% if name == "id" %> + <% next %> + <% end %> + <% if name == "created_at" %> + <% break %> + <% end %> +

+ +
+ value=<%= value %>> +

+ <% end %> -<%= tag(:label, for: 'GameType') %> \ No newline at end of file + <%= f.submit %> +<% end %> diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index a6dfa4d..428487a 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,6 +1,6 @@ <%= javascript_include_tag :defaults %> -

New tournament

+

New Tournament

<%= select_tag 'tournament_id', options_for_select(["Select a Game Type"] + Game.all.collect {|game| game.name}), :onchange => 'populate()' %> <%= link_to 'Select', 'new?game=1', :class => "btn btn-warning btn-lg" %> -- cgit v1.2.3-54-g00ecf