Help with output

I am having problems trying to get the output to work in an application I have. Here is the example

THIS GIVES ME THE CORRECT VALUES <!-- ######## Flooring ######### -->                   <% if(params[:flooring]) %>                     <tr><td colspan="4"><h2>Flooring</h2></td></tr>                     <% for company in @companies %>                           <% if(company.flooring == 1) %>                         <tr>                           <td><%= link_to company.name, company %></

                          <!--" + image_tag('view2.gif', :border => '0') + "-->

<% if session[:user_id] %>                             <td><%= link_to "[old view]", :controller => "companies", :action=> "show_org", :id => company.id %></td>                             <td><%= link_to "[edit]", edit_company_path(company) %></td>                             <td><%= link_to "[delete]", company, :confirm => 'Are you sure?', :method => :delete %></td>                           <% end %>                   <% end %>                       </tr>                     <% end %>                   <% end %>

THIS GIVES ME "#" INSTEAD OF THE CORRECT OUTPUT <!-- ######## Outdoor ######### -->                   <% if(params[:outdoor]) %>                     <tr><td colspan="4"><h2>Outdoor</h2></td></tr>                     <% for company in @companies %>

                      <%=h company.outdoor_wood_based_products %>                           <% if(company.outdoor_wood_based_products == 1 || company.outdoor_non_wood_based_products == 1) %>                         <tr>                           <td><%= link_to company.name, company %></

                          <!--" + image_tag('view2.gif', :border => '0') + "-->                             <% if session[:user_id] %>                             <td><%= link_to "[old view]", :controller => "companies", :action=> "show_org", :id => company.id %></td>                             <td><%= link_to "[edit]", edit_company_path(company) %></td>                             <td><%= link_to "[delete]", company, :confirm => 'Are you sure?', :method => :delete %></td>                           <% end %>                   <% end %>                       </tr>                     <% end %>                   <% end %>

could it be something in a model or controller

I'm guessing company.wood_based_products is an object or array or something other than a string?

If you see "#" on your page check the page source and see if there's more there, like #<Company: id: 1223...>, with everything in brackets hidden because it's treated as an xml tag.

If that's the case it should help you figure out what your problem is, probably trying to output something that isn't a string.

company.wood_based_products is a field in the database that holds either a 1 or a 0.

I am trying to test to see if it is a 1 and if so then to display details

  <%=h company.outdoor_wood_based_products %>                           <% if(company.outdoor_wood_based_products == 1 || company.outdoor_non_wood_based_products == 1) %>

gives me the following:

#<OutdoorWoodBasedProduct:0x1b07392> #<OutdoorWoodBasedProduct: 0x193973d> #<OutdoorWoodBasedProduct: 0x14346a4>#<OutdoorWoodBasedProduct: 0x1d2dc82>#<OutdoorWoodBasedProduct:0x8afd97> #<OutdoorWoodBasedProduct:0x17d40b7> #<OutdoorWoodBasedProduct: 0x1a52e8f> #<OutdoorWoodBasedProduct: 0x36c862>#<OutdoorWoodBasedProduct:0x9da031> #<OutdoorWoodBasedProduct:0x7272ca> #<OutdoorWoodBasedProduct: 0x11e7bb1> #<OutdoorWoodBasedProduct:0x58694a> #<OutdoorWoodBasedProduct:0x10c6ab0> #<OutdoorWoodBasedProduct: 0x1162955> #<OutdoorWoodBasedProduct:0x31a99a> #<OutdoorWoodBasedProduct:0x13ebb53> #<OutdoorWoodBasedProduct: 0x1b45d04>

Well without , obviously you're outputting an OutdoorWoodBasedProduct model somewhere repeatedly, or a collection of them -- my guess is <%=h company.outdoor_wood_based_products %>.

If that really is 1 or 0, then I don't know if I can help.

Do you have both a field and an association by the same name?

If you go into script/console, what is the output for:

Company.find(:first).outdoor_wood_based_products

What do you mean by a "field and an association by the same name"

I have a company table in my DB with a field called outdoor_wood_based_products

not sure I have a script console. I am new to this as you can tell and I am running Netbeans 6 with ruby as a plugin

I think the field and association may be my issue if I can figure out what you mean

I did change some filed names manually instead of using the migration tool

By a "field and an association by the same name" I mean do you have a field in your database table named 'outdoor_wood_based_products' as well as an association in your model ("has_many", "has_and_belongs_to_many", etc) that is also called 'outdoor_wood_based_products'.

In a console window (cmd if you're on Windows, or terminal if you're on UNIX/Mac), navigate to your base Rails project directory (c:/ myproject), and type "ruby script/console". That gives you an interactive ruby session with all the same libraries loaded as your webserver would see. That way you can create objects, call methods etc interactively through ruby without going through the browser.

Try that (it's an indispensable tool as you're developing),

Also paste in your Company.rb model so I can see what's going on, as well as the companies database schema definition.

MODEL for company

class Company < ActiveRecord::Base   has_many :facilities   has_many :green_products   has_many :discontinued_markets

  has_many :wood_based_building_system_products   has_many :non_wood_based_building_system_products   has_many :wood_windows_doors_products   has_many :non_wood_windows_and_doors_products   has_many :millwork_products   has_many :wood_based_panel_products   has_many :flooring_products   has_many :cabinetry_and_furniture_products   has_many :outdoor_wood_based_products   has_many :outdoor_non_wood_based_products   has_many :other_wood_based_building_products   has_many :other_non_wood_based_building_products   has_many :stone_processed_products_products   has_many :insulation_products

  after_update :save_facilities   after_update :save_green_products   after_update :save_discontinued_markets

  after_update :save_wood_based_building_system_products   after_update :save_non_wood_based_building_system_products   after_update :save_wood_windows_doors_products   after_update :save_non_wood_windows_and_doors_products   after_update :save_millwork_products   after_update :save_wood_based_panel_products   after_update :save_flooring_products   after_update :save_cabinetry_and_furniture_products   after_update :save_outdoor_wood_based_products   after_update :save_outdoor_non_wood_based_products   after_update :save_other_wood_based_building_products   after_update :save_other_non_wood_based_building_products   after_update :save_stone_processed_products_products   after_update :save_insulation_products

  def self.search(search)

    if search[:test]       province = search.delete(:province)

      test = search.delete(:test)       action = search.delete(:action)       controller = search.delete(:controller)       topdelcheckbox = search.delete(:topdelcheckbox)       sql = "0=0 and province LIKE ?"       varlength = search.length       counter = 1       if (varlength == 1)         sql += " and "       end       if (varlength >= 2)         sql += " and ("       end       search.each do |key, val|         if(key != "province")           if(key == "building_systems")             sql += "wood_based_building_systems = 1 or non_wood_based_building_system = 1"           elsif(key == "windows_and_doors")             sql += "wood_windows_and_doors = 1 or non_wood_windows_and_doors = 1"           elsif(key == "outdoor")             sql += "outdoor_wood_based_products = 1 or outdoor_non_wood_based_products = 1"           elsif(key == "other_building_products")             sql += "other_wood_based_building_products = 1 or other_non_wood_based_building_products = 1"           elsif(key == "wood_based_panels")             sql += "wood_based_panels = 1"           elsif(key == "millwork")             sql += "millwork = 1"           elsif(key == "cabinetry_and_furniture")             sql += "cabinetry_and_furniture = 1"           elsif(key == "flooring")             sql += "flooring = 1"           elsif(key == "stone_processed_products")             sql += "stone_processed_products = 1"           elsif(key == "insulation")             sql += "insulation = 1"

          end

          if (varlength != counter)             sql += " or "           end           counter = counter + 1         end       end       if (varlength >= 2)         sql += ") "       end

      find(:all, :conditions => [sql, "%#{province}%"], :order => "name")

    end   end

  def facility_attributes=(facility_attributes)     facility_attributes.each do |attributes|       if attributes[:id].blank?         facilities.build(attributes)       else         facility = facilities.detect { |t| t.id == attributes[:id].to_i}         facility.attributes = attributes       end     end   end

  def save_facilities     facilities.each do |t|       if t.should_destroy?         t.destroy       else         t.save(false)       end     end   end

  def green_product_attributes=(green_product_attributes)     green_product_attributes.each do |attributes|       if attributes[:id].blank?         green_products.build(attributes)       else         green_product = green_products.detect { |t| t.id == attributes[:id].to_i}         green_product.attributes = attributes       end     end   end

  def save_green_products     green_products.each do |t|       if t.should_destroy?         t.destroy       else         t.save(false)       end     end   end

  def discontinued_market_attributes=(discontinued_market_attributes)     discontinued_market_attributes.each do |attributes|       if attributes[:id].blank?         discontinued_markets.build(attributes)       else         discontinued_market = discontinued_markets.detect { |t| t.id == attributes[:id].to_i}         discontinued_market.attributes = attributes       end     end   end

  def save_discontinued_markets     discontinued_markets.each do |t|       if t.should_destroy?         t.destroy       else         t.save(false)       end     end   end

Company Schema

create_table "companies", :force => true do |t|     t.string "name"     t.string "contact"     t.string "title"     t.string "phy_add"     t.string "phy_post"     t.string "phy_city"     t.string "mail_add"     t.string "mail_post"     t.string "mail_city"     t.string "province"     t.string "phone"     t.string "fax"     t.string "url"     t.string "email"     t.string "owned_traded"     t.string "years_of_est"     t.string "employees"     t.string "perm_management"     t.string "perm_sales"     t.string "perm_trades"     t.string "total_per_capacity"     t.string "annual_sales"     t.integer "wood_based_building_systems"     t.integer "non_wood_based_building_system"     t.integer "wood_windows_and_doors"     t.integer "non_wood_windows_and_doors"     t.integer "millwork"     t.integer "wood_based_panels"     t.integer "flooring"     t.integer "cabinetry_and_furniture"     t.integer "outdoor_wood_based_products"     t.integer "outdoor_non_wood_based_products"     t.integer "other_wood_based_building_products"     t.integer "other_non_wood_based_building_products"     t.integer "stone_processed_products"     t.integer "insulation"     t.integer "focus_niche"     t.integer "focus_mass_volume"     t.integer "focus_comp_price"     t.integer "focus_high_quality"     t.string "annual_prod_green"     t.text "green_planning"     t.string "leed_cert"     t.text "leed_cert_exp"     t.text "specific_cert"     t.string "years_exp_out_canada"     t.string "total_annual_sales"     t.integer "inc_in_exp_sales"     t.string "inc_in_exp_sales_amnt"     t.string "current_export_local"     t.text "new_export_int"     t.string "prim_customer_a"     t.integer "discontinued_exporting"     t.string "prim_customer_b"     t.string "prim_customer_c"     t.text "dist_channels"     t.integer "has_business_plan"     t.integer "has_export_plan"     t.integer "has_commitment"     t.integer "does_access_market"     t.integer "does_identify_regulations"     t.integer "does_utilize_trade"     t.integer "does_trade_mission"     t.integer "does_trade_show"     t.integer "does_in_market_visit"     t.integer "does_other"     t.text "does_other_explain"     t.integer "hr_management"     t.text "hr_management_gap"     t.integer "hr_experience"     t.text "hr_experience_gap"     t.integer "hr_trades"     t.text "hr_trades_gap"     t.integer "hr_other_skills"     t.text "hr_other_skill_gap"     t.integer "pr_raw_materials"     t.text "pr_raw_materials_gap"     t.integer "pr_modification"     t.text "pr_modification_gap"     t.integer "pr_equip_tech"     t.text "pr_equip_tech_gap"     t.integer "pr_processes"     t.text "pr_processes_gap"     t.integer "pr_quality"     t.text "pr_quality_gap"     t.integer "pr_lic_cert"     t.text "pr_lic_cert_gap"     t.integer "pr_infrastructure"     t.text "pr_infrastructure_gap"     t.integer "or_adequate_fin"     t.text "or_adequate_fin_gap"     t.integer "or_pricing_str"     t.text "or_pricing_str_gap"     t.integer "or_deadlines"     t.text "or_deadlines_gap"     t.integer "or_website"     t.text "or_website_gap"     t.integer "or_material"     t.text "or_material_gap"     t.integer "partner_with_companies"     t.text "partner_with_companies_arr"     t.text "challenges"     t.text "beneficial"     t.text "assist_company_exporting"     t.text "company_desc"     t.text "additional_comments"     t.datetime "created_at"     t.datetime "updated_at"   end

I don't have a ruby directory in my application folder so I don't think I can run the console

Yup. You've defined a "has_many" association called "outdoor_wood_based_products" and you also have a database column by the same name. Can't have both -- they do different things.

You don't need a ruby directory in your application directory. All you need is ruby to be in your execution path. I'd imaging NetBeans also has a "console" button, but I don't have it in front of me.

Anyway, that's you're problem. Calling two distinct things by the same name.

Man I thank you a million. I spent the last 4 hours working on this

I just tried you suggestion and it worked great. Thank you so much for spending the time with me. I am a newbie and having someone around like you is a life saver.

It would be great to be able to contact you if I had any more questions. Would you mind.

No I don't mind helping. What goes around comes around. Just so long as you make a reasonable attempt to figure it out on your own first :slight_smile:

For sure, I respect that. Thanks again.