ScottishTapWater
ScottishTapWater

Reputation: 4806

POST args to method rails

I'm trying to wrap my head around forms on rails and am attempting to implement a very simple registration page. Essentially, it's going to take a name and an email, sterilise the parameters and then chuck it into MySQL.

I have this code for generating the form:

  <%= form_tag(controller: "root", action: "register", method: "post", class: "root") do %>
      <%= label_tag(:n, "Name:") %>
      <%= email_field(:n, "name") %>
      <%= label_tag(:e, "Email:") %>
      <%= email_field(:e, "email") %>
      <%= submit_tag("Register") %>
  <% end %>

Which seems to work, this is the route:

  post '/' => 'root#register'

Which also seems to work fine, and this is the controller:

class RootController < ApplicationController
  def root

  end

  def register(name,email)

  end
end

However, I receive the following error, so I'm wondering how I stick my args into my POST request so that they get passed to the method.

Error Screenie

I've had a look around Google and can't seem to get an answer.

Upvotes: 1

Views: 51

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230346

Yep, that's now you handle parameters in rails. This is how.

def register
  name = params[:name]
  email = params[:email]
  ...
end

Upvotes: 4

Related Questions