I
I
izac2015-11-09 02:45:50
Ruby on Rails
izac, 2015-11-09 02:45:50

Rails How to display POST variables in a form?

Hello, I can’t display variables from POST in Rails
, I have a display with a form

<h1>Formularz nowego uzytkownika</h1>
<%= form_tag({ :action => 'show' }, { :method => :post }) do %>
  <%= label_tag("Name:") %>
  <%= text_field("person", "name") %><br/><br/>

  <%= submit_tag("Ok") %>
<% end %>

There is a controller method but how to transfer variables from POST to another form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
izac, 2015-11-09
@izac

Found the answer:
in the display there should be such a code

<%= form_tag("/user/show", method: "post") do %>
  <%= label_tag("name:") %>
  <%= text_field_tag("name") %><br/><br/>
    <%= label_tag("surname:") %>
  <%= text_field_tag("surname") %><br/><br/>
    <%= label_tag("Age:") %>
  <%= text_field_tag("age") %><br/><br/>

  <%= submit_tag("Ok") %>
<% end %>

In the controller, this code
class UserController < ApplicationController
  def index
  	 #@user = User.new
  end
  def show
  	@name = params[:name]
  	@surname = params[:surname]
  	@age = params[:age]
  end
end

In 2 display such
<h1>Show</h1>
<div clas="form">
name:<%= @name %><br/>
surname:<%= @surname %><br/>
age:<%= @age %><br/>
</div>

<%= link_to('Click here', controller: 'pages',
        action: 'index') %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question