Sorry to post two newbie questions in one day :) I''m trying to make a new Character row in my database. It has several values in the row, but I only need 2 or so from the user and the rest can be figured out by the app. My problem is I''m having trouble figuring out how to get a specific value from params. For the record, I''m still in Rails 1.2.6. So the form for the Character object should gather the Character''s codename, as well as the Character''s Power Level. I want to gather the two paramters, do some calculations, and then actually do the creation, rather than having the user hard code all the values in a form and doing mass assignment. So, the form I have now looks like this: <% form_tag(:action => ''create'') do %> <%= text_field ''character'', ''codename'' %> <%= text_field ''character'', ''power_level'' %> <%= submit_tag "Create Character" %> <% end %> I expect my create method will contain something like this: character = Character.new do |c| c.codename = [Codename Parameter] c.power_level = [Powerlevel Parameter] c.power_points = [Powerlevel Parameter * 15] ... end However, I can''t figure out how to retrieve the individual values brought over from the form. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I just thought that I might be overthinking it, and I would be able to do: character = params[:character] @codename = character.codename But when I tried to print out @codename in a temporary view, it gave me an error for calling an undefined method. On Jan 16, 9:50 pm, DVG <devry...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sorry to post two newbie questions in one day :) > > I''m trying to make a new Character row in my database. It has several > values in the row, but I only need 2 or so from the user and the rest > can be figured out by the app. My problem is I''m having trouble > figuring out how to get a specific value from params. > > For the record, I''m still in Rails 1.2.6. > > So the form for the Character object should gather the Character''s > codename, as well as the Character''s Power Level. > > I want to gather the two paramters, do some calculations, and then > actually do the creation, rather than having the user hard code all > the values in a form and doing mass assignment. > > So, the form I have now looks like this: > <% form_tag(:action => ''create'') do %> > <%= text_field ''character'', ''codename'' %> > <%= text_field ''character'', ''power_level'' %> > <%= submit_tag "Create Character" %> > <% end %> > > I expect my create method will contain something like this: > character = Character.new do |c| > c.codename = [Codename Parameter] > c.power_level = [Powerlevel Parameter] > c.power_points = [Powerlevel Parameter * 15] > ... > end > > However, I can''t figure out how to retrieve the individual values > brought over from the form.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nevermind, I think I have it. params[:character].fetch(''codename'') Seems to look right. On Jan 16, 9:53 pm, DVG <devry...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I just thought that I might be overthinking it, and I would be able to > do: > character = params[:character] > @codename = character.codename > > But when I tried to print out @codename in a temporary view, it gave > me an error for calling an undefined method. > > On Jan 16, 9:50 pm, DVG <devry...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Sorry to post two newbie questions in one day :) > > > I''m trying to make a new Character row in my database. It has several > > values in the row, but I only need 2 or so from the user and the rest > > can be figured out by the app. My problem is I''m having trouble > > figuring out how to get a specific value from params. > > > For the record, I''m still in Rails 1.2.6. > > > So the form for the Character object should gather the Character''s > > codename, as well as the Character''s Power Level. > > > I want to gather the two paramters, do some calculations, and then > > actually do the creation, rather than having the user hard code all > > the values in a form and doing mass assignment. > > > So, the form I have now looks like this: > > <% form_tag(:action => ''create'') do %> > > <%= text_field ''character'', ''codename'' %> > > <%= text_field ''character'', ''power_level'' %> > > <%= submit_tag "Create Character" %> > > <% end %> > > > I expect my create method will contain something like this: > > character = Character.new do |c| > > c.codename = [Codename Parameter] > > c.power_level = [Powerlevel Parameter] > > c.power_points = [Powerlevel Parameter * 15] > > ... > > end > > > However, I can''t figure out how to retrieve the individual values > > brought over from the form.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---