Forms without the helpers

Hi there!

I’m a bit of a rails newbie, and I’ve had success as long as I followed
rails conventions and used the form helpers. But now I want to do
something a little different and I’m already stumped. I want to pass
some form data into the controller, but it’s not related to a database
model or anything like that. Here’s what I have in my view:

<%= start_form_tag :action => ‘testing’ %>

<%= submit_tag “Create” %>
<%= end_form_tag %>

I guess I’m not sure how to access the form data named “foo” in the
controller. Is it something sort of like this:

def testing(foo)
@bar = foo
end

Thanks for the help in advanced. I’m guessing this is pretty simple, but
I’m new to ruby, rails, and programming in general.

Dave

Here’s what belongs in your controller:
def testing
@bar = params[:foo]
end

You should change your view not to user
start_form_tag…end_form_tag, it’s deprecated. Here’s how instead:
<% form_tag :action=> ‘testing’ do %>

<% end %>
Notice those are in <% %>, not <%= %>.
Andy

On 5/4/07, Dave A. [email protected] wrote:

<%= start_form_tag :action => ‘testing’ %>

Thanks for the help in advanced. I’m guessing this is pretty simple, but
I’m new to ruby, rails, and programming in general.

Dave

To get access to parameters you need to use the params method

def testing
@bar = param[:foo]
end

Cheers

def testing
@bar = param[:foo]
end

Thanks to both of you! Worked perfectly.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs