简体   繁体   中英

How do i create a simple form and show the entered values when user submit data in RoR

I am new to Ruby on Rails. I am trying to create a form and submit it and show the submitted values in a page. But i am getting error most often, can any one help me to work around this with any simple example or simple link?

Thanks, Balan

Simplest way to create a form without REST is

<%= form_tag '/some_path' do %>
   <%= text_field_tag :name %>
   <%= submit_tag %>
<% end %>

and then you can get to the value of the text field via params[:name] . This will be available in a controller, for example.

# routes.rb

match "/something" => "home#something"

# home_controller.rb

class HomeController < ApplicationController
  def something
    # this will output raw text/plain with the content submitted via the form
    render :text => params[:name]
  end
end

It would be helpful if you could provide exactly what error are you getting and an example of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM