Adventure Time - Finn 3
본문 바로가기
카테고리 없음

루비 데이터 받아보기

by hyun9_9 2024. 5. 24.

index.erb

<head>
	<%= csrf_meta_tags %>	
</head>

<form action="result" method ="POST">
	<input type="number" name="num1"> + <input type="number" name="num2">
	<input type="submit">
</form>

html 작성

 

home_controller.rb

class HomeController < ApplicationController
	def index	
	end

	
	def result
		@plus_result = params[:num1].to_i + params[:num2].to_i
	end
end

 

params[:num1] => num1 이라는 name 의 value 를 가져옴 => 문자열 형태

.to_i => int 형변환

 

routes.rb

연결