Hunter Walker
2006-May-09 23:44 UTC
[Rails] Create checkboxes on page using contents of a hash
Hi all,
I have a hash that is created in the index method of my controller.
After it is created, the index.rhtml page is rendered. Upon this
rendering I would like to create a check box for each key/value in the
hash.
The has is @recordsHash
I have been trying varying stratagies like the one below, but to no
avail. Do you have any ideas? Thanks for your help on this!
html lang=''en">
<head>
</head>
<body>
Some text here
</br>
<%= form_tag(:controller => "AddMassMail", :action =>
''addmassmail'') %>
<% @recordsHash.each do {|key, value| %>
<%= "Site #{value}<%= check_box(''Site'',
''#{key}'', {:checked
=> ''checked''}, ''yes'') %> <% } %>
<%= submit_tag("Add Mass Mailing") %>
<%= end_form_tag %>
</body>
</html>
--
Posted via http://www.ruby-forum.com/.
Hunter Walker wrote:> Hi all, > > I have a hash that is created in the index method of my controller. > After it is created, the index.rhtml page is rendered. Upon this > rendering I would like to create a check box for each key/value in the > hash. > > >Think you have an error in your each iteration. Believe the correct syntax is: some_hash.each { |key, value| #something here } or some_enumerable.each do |key, value| #something here end> <%= form_tag(:controller => "AddMassMail", :action => ''addmassmail'') %> > > <% @recordsHash.each do {|key, value| %> > <%= "Site #{value}<%= check_box(''Site'', ''#{key}'', {:checked > => ''checked''}, ''yes'') %> <% } %> > > >
Hunter Walker
2006-May-10 15:22 UTC
[Rails] Re: Create checkboxes on page using contents of a hash
Chris T wrote:> Hunter Walker wrote: >> Hi all, >> >> I have a hash that is created in the index method of my controller. >> After it is created, the index.rhtml page is rendered. Upon this >> rendering I would like to create a check box for each key/value in the >> hash. >> >> >> > Think you have an error in your each iteration. Believe the correct > syntax is: > > some_hash.each { |key, value| #something here } > > or > > some_enumerable.each do |key, value| > #something here > endHi Chris, I tried both of those but I am still getting syntax errors: <% @recordsHash.each do |key, value| %> <%= "Site #{value}<%= check_box(''Site'', ''#{key}'', {:checked => ''checked''}, ''yes'') %> I may have to create true objects. This is just an API calling app, so I was hoping to keep it simple, but I can''t get this last part working. Bummer! -- Posted via http://www.ruby-forum.com/.
Chris T
2006-May-10 17:38 UTC
[Rails] Re: Create checkboxes on page using contents of a hash
Hunter Walker wrote:> Chris T wrote: > >> Hunter Walker wrote: >> >>> Hi all, >>> >>> I have a hash that is created in the index method of my controller. >>> After it is created, the index.rhtml page is rendered. Upon this >>> rendering I would like to create a check box for each key/value in the >>> hash. >>> >>> >>> >>> >> Think you have an error in your each iteration. Believe the correct >> syntax is: >> >> some_hash.each { |key, value| #something here } >> >> or >> >> some_enumerable.each do |key, value| >> #something here >> end >> > Hi Chris, > > I tried both of those but I am still getting syntax errors: > > <% @recordsHash.each do |key, value| %> > > <%= "Site #{value}<%= check_box(''Site'', ''#{key}'', {:checked => > ''checked''}, ''yes'') %> > > > I may have to create true objects. This is just an API calling app, so > I was hoping to keep it simple, but I can''t get this last part working. > Bummer! > >What exactly is the syntax error? Maybe an email typo but think you''re also missing a %> after #{value} and I thought you needed to use double quotes for ruby to see the #{} construction, so it would need to be: <%= check_box(''Site'', "#{key}",... though would have thought you could skip the quotes and #{} completely: <%= check_box(''Site'', key,...
Hunter Walker
2006-May-10 23:56 UTC
[Rails] Re: Re: Create checkboxes on page using contents of a hash
I agree, but I am still getting an unhelpful syntax error from Rails
Here is my code:
<%= form_tag(:controller => "AddMassMail", :action =>
''addmassmail'') %>
<% @recordsHash.each do |key, value| %>
<%= value %> <%= check_box(''Site'', key,
{:checked => ''checked''},
''yes'') %> </br>
<%= submit_tag("Add Mass Mailing") %>
<%= end_form_tag %>
Here is the error. Thank you for your continued help.
SyntaxError in Add_mass_mail#index
Showing app/views/add_mass_mail/index.rhtml where line #27 raised:
compile error
./script/../config/../app/views/add_mass_mail/index.rhtml:27: syntax
error
Extracted source (around line #27):
24:
25: </body>
26: </html>
Trace of template inclusion: /app/views/add_mass_mail/index.rhtml
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/views/add_mass_mail/index.rhtml:27:in `module_eval''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:496:in
`module_eval''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:496:in
`compile_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:300:in
`compile_and_render_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:285:in
`render_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:244:in
`render_file''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:697:in
`render_file''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:619:in
`render_with_no_layout''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/layout.rb:251:in
`render_without_benchmark''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`measure''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:909:in
`perform_action_without_filters''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:355:in
`perform_action_without_benchmark''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`measure''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/rescue.rb:82:in
`perform_action''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`send''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`process_without_filters''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:364:in
`process_without_session_management_support''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/session_management.rb:117:in
`process''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:38:in
`dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service''
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread''
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread''
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each''
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__''
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__''
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require''
script/server:3
#{RAILS_ROOT}/app/views/add_mass_mail/index.rhtml:27:in `module_eval''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:496:in
`module_eval''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:496:in
`compile_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:300:in
`compile_and_render_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:285:in
`render_template''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:244:in
`render_file''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:697:in
`render_file''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:619:in
`render_with_no_layout''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/layout.rb:251:in
`render_without_benchmark''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`measure''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:909:in
`perform_action_without_filters''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:355:in
`perform_action_without_benchmark''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`measure''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/rescue.rb:82:in
`perform_action''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`send''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`process_without_filters''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:364:in
`process_without_session_management_support''
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/session_management.rb:117:in
`process''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:38:in
`dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service''
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread''
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread''
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each''
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__''
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__''
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require''
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require''
script/server:3
Request
Parameters: None
Show session dump
---
flash: !ruby/hash:ActionController::Flash::FlashHash {}
Response
Headers: {"cookie"=>[],
"Cache-Control"=>"no-cache"}
--
Posted via http://www.ruby-forum.com/.
Adam Bloom
2006-May-11 00:36 UTC
[Rails] Re: Re: Create checkboxes on page using contents of a hash
><%= value %> <%= check_box(''Site'', key, {:checked => ''checked''}, >''yes'') %> </br>You''re missing a <% end %> after this line. -Adam -- Posted via http://www.ruby-forum.com/.
Hunter Walker
2006-May-11 03:50 UTC
[Rails] Re: Re: Create checkboxes on page using contents of a hash
Adam Bloom wrote:>><%= value %> <%= check_box(''Site'', key, {:checked => ''checked''}, >>''yes'') %> </br> > > You''re missing a <% end %> after this line. > > -AdamYou are correct, sir. Thanks to both of you for the help! I appreciate it! -- Posted via http://www.ruby-forum.com/.