Reputation: 181
I created a form that you can type text with a "post" button and i want that when you type something and press the post button it will show what you wrote.
My question is: What is the code to connect between the view and the controller?
This is the view i already created:(i also generated a home controller with a showmsg action)
<h1 align="center">MicroBlog</h1>
<br><br>
<div align="center">
<%= form_tag( {:controller => 'home', :action => 'showmsg'}, :method => "post") do %>
<%= text_field_tag(:p,@postword) %>
<%= submit_tag("post") %>
<% end %>
</div>
how should the showmsg action would look like so i could show the msg? thank you very much!
Upvotes: 1
Views: 1171
Reputation: 40277
Your controller will need to access the param being sent to it, assign it to an instance variable, which your view will then be able to access.
class HomeController < ApplicationController
def showmsg
@message = params[:p]
end
end
/app/views/home/showmsg.html.erb
...
<%= @message %>
...
Upvotes: 3