Forum: Nitro Passing Data from Template to Controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5f65ee21e577b094753cd7d854dc39e4?d=identicon&s=25 Matthew B Gardner (Guest)
on 2007-12-16 06:25
(Received via mailing list)
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...
<input type="text" name="keywords" size="45" />

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
Bd10252dc68b39171cc9bf5f74bcb9f1?d=identicon&s=25 Arne Brasseur (Guest)
on 2007-12-16 07:54
(Received via mailing list)
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:


<form method="post" action="...">
<input type="text" name="keywords" size="45" />

...

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ß
arne@arnebrasseur.net
5f65ee21e577b094753cd7d854dc39e4?d=identicon&s=25 Matthew B Gardner (Guest)
on 2007-12-16 08:05
(Received via mailing list)
Hello --

On Sunday 16 December 2007 01:53, Arne Brasseur 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
This topic is locked and can not be replied to.