Dominic L.
Dominic L.

Reputation: 75

Creating & accessing a simple Ruby on Rails Form

I want to create the following:

The user types a text into a TextField and clicks 'submit'. The text is then given to my ruby application which modifies certain bits of it and then displays it on the website.

The problem I am having is that I do not know how to create this textfield and how to access the content of that textfield in my application.

(All the tutorials I have looked at that use forms use a Model. Michael Hartl in chapter 7 for example writes signup page and just uses user/new as his signup page. Do I have to create a Model for my textfield as well then? It seems a bit over the top to create a model just for a simple form?)

Upvotes: 0

Views: 29

Answers (1)

Michał Młoźniak
Michał Młoźniak

Reputation: 5556

You can just use form_tag helper to create form not connected to any model like:

<%= form_tag '/some_action_url' do %>
  <%= text_field_tag 'my_field' %>
  <%= submit_tag 'Send' %>
<% end %>

You can grab value of text field from params[:my_field] in your controller.

Upvotes: 1

Related Questions