Rod Bradley
2007-Jan-10 17:17 UTC
Unable to get input for certain fields to post to mySQL db
I am just a little bit beyond customizing my scaffolding. Another way of saying I am a Rails Rookie : ) Here is my problem: About 50% of the code in my view below is working. Example: <p><b>First Name</b><br/><input id="first_name" name="rlm[first_name]" size="30" type="text" value=""/></p><p> However. anything that is contained within <%= /> will not write to the db. Example 1: <p> <b>Hope for the Homeless Youth:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> Example 2: <p> <b>1A Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> What do I need to do in the controller, model, view, helper, etc to get it to write these values to the db? My date fields are defined as date and my question fields as text in mySQL. Below is my new.rhtml code which is working for 50% of the fields, but again anything with a <%xxxxxxx /> will not insert into mySQL db. Thanks again for your help! new.rhtml code below. <html> <head> <title>New Contact</title> </head> <body> <h1>New Contact</h1> <form action="/rlm/create" method="post"> <p> <b>First Name</b><br/> <input id="first_name" name="rlm[first_name]" size="30" type="text" value=""/> </p> <p> <b>Last Name</b><br/> <input id="last_name" name="rlm[last_name]" size="30" type="text" value=""/> </p> <p> <b>Address1</b><br/> <input id="address1" name="rlm[address1]" size="30" type="text" value=""/> </p> <p> <b>Address2</b><br/> <input id="address2" name="rlm[address2]" size="30" type="text" value=""/> </p> <p> <b>City</b><br/> <input id="city" name="rlm[city]" size="30" type="text" value=""/> </p> <p> <b>State</b><br/> <input id="state" name="rlm[state]" size="30" type="text" value=""/> </p> <p> <b>Zip</b><br/> <input id="zip" name="rlm[zip]" size="30" type="text" value=""/> </p> <p> <b>Country</b><br/> <input id="country" name="rlm[country]" size="30" type="text" value=""/> </p> <p> <b>Home Phone</b><br/> <input id="home_phone" name="rlm[home_phone]" size="12" type="text" value=""/> </p> <p> <b>Cell Phone</b><br/> <input id="cell_phone" name="rlm[cell_phone]" size="12" type="text" value=""/> </p> <p> <b>Work Phone</b><br/> <input id="work_phone" name="rlm[work_phone]" size="12" type="text" value=""/> </p> <p> <b>Other Phone</b><br/> <input id="other_phone" name="rlm[other_phone]" size="12" type="text" value=""/> </p> <p> <b>Work Email</b><br/> <input id="email_work" name="rlm[email_work]" size="40" type="text" value=""/> </p> <p> <b>Personal Email</b><br/> <input id="email_personal" name="rlm[email_personal]" size="40" type="text" value=""/> </p> <p> <b>Website</b><br/> <input id="website" name="rlm[website]" size="40" type="text" value=""/> </p> <p> <b>Occupation</b><br/> <input id="occupation" name="rlm[occupation]" size="30" type="text" value=""/> </p> <p> <b>Church Affiliation</b><br/> <input id="church_affiliation" name="rlm[church_affiliation]" size="25" type="text" value=""/> </p> <p> <b>Hope for the Homeless Youth:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>Personal Ministry Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> <b>Personal Ministry End Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>1A Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>1A Certificate Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>1B Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>1B Certificate Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>2A Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>2A Certificate Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>2B Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>2B Certificate Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>3A Start Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>3A Certificate Date</b><br/> <%= date_select ("post","written_on",:start_year => 1980,:use_month_numbers => false,:include_blank => true,:order => [:month,:day,:year])%> </p> <p> <b>RLM Teacher:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>RLM Assistant:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>RLM Board Member:</b><br/> <select name="rlm[choice_id]"> <% @ choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>RLM Donor:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>RLM Volunteer:</b><br/> <select name="rlm[choice_id]"> <% @choices.each do |choice| %> <option value="<%= choice.id %>"> <%= choice.name %> </option> <% end %> </select> </p> <p> <b>RLM Gifting</b><br/> <textarea cols="40" id="Rlm_gifting" name="rlm[Rlm_gifting]" rows="20" wrap="virtual"> </textarea> </p> <p> <b>Notes</b><br/> <textarea cols="40" id="notes" name="rlm[notes]" rows="20" wrap="virtual"> </textarea> </p> <input type="submit" value="Create"/> </form> <a href="/rlm/list">Back</a> </body> </html> below is my controllers class RlmController < ApplicationController scaffold :rlm def new @rlms = Rlm.new @choices = Choice.find_all end def edit @rlm = Rlm.find(@params["id"]) @choices = Choice.find_all end end class ChoiceController < ApplicationController scaffold :choice end below are my models class Rlm < ActiveRecord::Base belongs_to :choice end class Choice < ActiveRecord::Base has_many :rlms end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2007-Jan-10 18:14 UTC
Re: Unable to get input for certain fields to post to mySQL db
Hi Rod, The first thing I''d recommend is that you switch to using explicit scaffolding. It''ll give you a better default view of how Rails works. The use of the implicit scaffolding technique has pretty much come to be seen as something that''s better left until someone''s reached a fairly advanced knowledge of Rails and what it does by default. To address your question more directly, I''m not sure the mix of Rails and HTML you''ve got in your view below is going to work. I could be wrong, but with the form tags being in html but the fields you want to return to the server being in embedded Ruby, I''d be surprised if Rails is generating the form html you need. Take a look at your page source and have a look. WRT advancing your understanding of Rails, O''Reilly just published the second part of the updated "Rolling with Ruby on Rails" tutorial. It uses the explicit scaffolding. http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html?page=1 Depending on what else you''ve already done, that might be a good place to start (please forgive the shameless self-delivered-plug). hth, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---