GeekToL
GeekToL

Reputation: 1815

Submit form, don't save Into database, and display on page - Rails

I have one form on index page, when submit to some page (ex : localhost:3000/:domainame), I want it don't save into database and display some data.

def index
end

def who
  w = Whois::Client.new(:timeout => 20)
  @domainlook = w.lookup(params[:domainname])
end

How can i do it?

Upvotes: 0

Views: 591

Answers (1)

zeantsoi
zeantsoi

Reputation: 26193

A very simple example implementation leveraging your sample code:

Create a POST match route:

# config/routes.rb
match 'who' => 'home#who', :via => :post

Set up a controller action for the route:

# app/controllers/home_controller.rb
def index
end

def who
    w = Whois::Client.new(:timeout => 20)
    @domainlook = w.lookup(params[:domainname])
end

The index.html.erb view should contain a form using the form_tag helper:

# app/views/home/index.html.erb
<%= form_tag who_path do %>

    <%= label_tag :domainname %>
    <%= text_field_tag :domainname %>

<% end %>

Finally, the who.html.erb view will render out your non-model instance variable:

# app/views/who.html.erb
<%= @domainlook %>

Upvotes: 3

Related Questions