Passing Data from Template to Controller

Hello –
I’m working on a form to create helpfiles, which seems to be working
fine.
However, the problem I’m having is how to pass entered keywords from the
template to the controller, where I can manipulate the data. I don’t
want to
save the keywords to the database as a string column for the helpfile –
instead, I want to take the keywords string and split it up into single
words, and then add those words to their own table (has_many/belongs_to
relationship). I can’t figure out how to pass that keywords string back
to
the controller though, because it only seems to take data if the
variable has
an Og association. To clarify, I’m trying to do this…

model…
class HelpFile
attr_accessor :keywords
end

template…

controller…
def create_hfile
h = request.assign(HelpFile.new)
kwords = h.keywords.split

end

Thanks for any help or ideas (maybe a better way to do this?),
Matt

You can access the individual fields in the request to do your own
processing. I think this is what you’re looking for.

Something to this effect:

def create_hfile
h = request.assign(HelpFile.new)
request.post[‘keywords’].split.each do |kw|
h.keywords << KeyWord.create_with(:keyword => kw)
end
end

Does that help you?
(ab)

Matthew B Gardner schreef:

h = request.assign(HelpFile.new)


Ein Fuchs muß tun, was ein Fuchs tun muß
[email protected]

Hello –

On Sunday 16 December 2007 01:53, Arne B. wrote:

Exactly what I was looking for – thanks so much. I did get an error
regarding
the request#post call (undefined method), but it works fine with
directly
accessing request[‘keywords’].

Thanks again, it’s very appreciated.
-Matt