I'm new to ruby and rails and I have a simple question that is driving
me crazy. I have a group of check boxes and I want to be able to
default check some of them based on entries in a database.
My display.rhtml looks like this:
<% for category in @categories %>
<dd><%= check_box "category", category.id %><%= category.name %></dd>
<dt> </dt>
<% end %>
If I was writing in HTML I would add a CHECKED option to the checkbox
tag to have it default to checked. How do I do that with ruby?
i.e., in your above example,
<%= check_box "category", category.id, category.my_boolean_attribute?
%>
Would check the checkbox if category.my_boolean_attribute? returned
true and would leave it unchecked otherwise.
Returns a checkbox tag tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). It's intended that method returns an integer and if that integer is above zero, then the checkbox is checked. Additional options on the input tag can be passed as a hash with options. The checked_value defaults to 1 while the default unchecked_value is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don't post anything. We work around this problem by adding a hidden value with the same name as the checkbox.
So your category_id seems to be in the wrong place.
My apologies if this is a excessively newbish question.
Is there way to get one's rails app loaded into fxri such that I can use it
with Rails to explore what I can do with the different objects of my Rails
application?
Not having used fxri before, it should just be a matter of requiring your config/environment.rb file. Once you do that, you should have all of your Rails app before you, ready to query.
- Jamis
···
On Jun 21, 2005, at 12:48 PM, Jeff Waltzer wrote:
My apologies if this is a excessively newbish question.
Is there way to get one's rails app loaded into fxri such that I can use it
with Rails to explore what I can do with the different objects of my Rails
application?
My apologies if this is a excessively newbish question.
Is there way to get one's rails app loaded into fxri such that I can use it
with Rails to explore what I can do with the different objects of my Rails
application?
Yes you can use "rdoc --ri <your-rails-app-dir>" and it will generate
the data for the database. But make sure that you don't extend
existing classes like STRING as they are removed.
I work on an easy way to do so with "Arachno Ruby" as the current
ri/rdoc implementation is not the best.
···
--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's