Topic: Concatenate Fields while those are getting entered and assign them

Pardon me for my li'l knowledge as I'm a naive Ruby Programmer. In my view for _form.rhtml, when user enters a few fields, I need to concatenate all those and set them in Real number field.

I'm using this currently which doesn't get the results apparently since I haven't set them in the @subreq variable, How to set them?

field_a <%= text_field :subreq, :field_a, :size => 11 %> <br><br>
field_b <%= text_field :subreq, :field_b, :size => 5 %> <br><br>

Real number &nbsp; <%= @subreq.field_a unless @subreq.field_a.nil? %> <%= @subreq.field_b unless @subreq.field_b.nil? %>

Re: Concatenate Fields while those are getting entered and assign them

You are probably going to have to do some javascript to set a couple of variables that you can then use in the calc.  (I don't know how)

Re: Concatenate Fields while those are getting entered and assign them

If I try to concatenate the fields in my model, How can I access that variable in my Controller or the views?

def real_number
  "#{field_a} #{field_b}"
end
How can I access real_number and also, how to set this value in @subreq array so that it gets updated in the Database?

Re: Concatenate Fields while those are getting entered and assign them

I defined the field real_number in my model as stated above and wrote the following statement in my controller before calling @subreq.save and it worked...Whoa!

@subreq.real_num = @subreq.real_number