I’m a newbie with ruby-rails (also with web
developpement) I want to create a form to get data
from the user, like text field and combobax, button,
etc. I used “text_field_tag” or other “tag” to
genenate those components on the html, but after that
I have no idea how to get the data from the
components, I read the examples and documentations
about how to create the componenets, but I didn’t find
anything which talk about how to extract them… Can
someone please tell me how to do it or where can I
find the documentation!!!
anything which talk about how to extract them… Can
someone please tell me how to do it or where can I
find the documentation!!!
Is there any particular reason you’re using ‘tag’ and
‘text_field_tag’? It’s usually much simpler to use the form
helpers. For example, in a view such as edit.rhtml:
<%= text_field ‘user’, ‘name’ %>
and then in your controller you could access the user’s name via:
def edit @name = params[:user][:name]
end
If you need further help, perhaps you can be more specific with your
question or show examples of what you’ve already tried and why.
the reason I use “_tag” is because I don’t have a
model (no database) If I understand well the mecanism,
the helpers without “tag”, they send information
directly to the model…so that’s why I didn’t used
them.
After a lot of tryings, I find out that I can get the
info from the variable “@params”, like
"@params[‘post’], but I don’t know if it is the
correct way to get the information.
Thanks you very much
sayoyo
this is an example.
def buildTable
if @params.include?(‘post’) then @checkTextField = @params[‘post’]
else @checkTextField = nil
end
end
You may consider using the convention of underscores instead of
camelCase, e.g.: start_form_tag :action => build_table. It’s a Ruby
convention that Rails sometimes relies on for conversion between
camelCase and underscored variables.
The above two lines look a little odd to me… you’re assigning the
variable called ‘value’ twice, but then not using it below. Perhaps
you meant to use a symbol-as-key hash like this: