ヂサキノブログ

Android Xperia root取り MNP一括0円 陸マイラー ANA SFC修行 等のblogです

Ruby on Railsで簡単webアプリケーション開発 3日目でつまってます

人力検索で質問した件はこちらです。

症状は

1  = の後に答えが表示されません。

2 右の入力欄を更新するたび、入力欄が増えていってしまいます。

3 画面の下の方に計算利敵が表示されるはずですが表示されません。

4 下に掲載した4つのファイルを添付CD-ROMからコピーしても症状は同じでした。

下に私が入力したソースを載せておきます。

2つの入力欄に入力した数字を四則演算するプログラムです。


私の環境

Windows Vista x64 SP1 RC

ActiveScriptRuby 1.8.6

LOCAL GEMS ***

actionmailer (1.3.6)

actionpack (1.13.6)

actionwebservice (1.2.6)

activerecord (1.15.6)

activesupport (1.4.4)

postgres-pr (0.4.0)

rails (1.2.6)

rake (0.8.1)

rubygems-update (1.0.1)

sources (0.0.1)

calc_controller.rb

class CalcController < ApplicationController
def console
end
def calc
@result = calculate
render :partial => 'result'
end
def update
@result = "#{params[:left]} #{params[:operator]} #{params[:right]} = #{calculate}"
render :partial =>'update_result'
end
def calculate
if ['+','-','*','/'].include?(params[:operator])
return params[:left].to_i.send(params[:operator],params[:right].to_i)
end
0
end
end

console.rhtml

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<%= javascript_include_tag "prototype" %>
<title>calculator</title>
<style type="text/css" media="screen">
#left{ text-align: right; }
#right{ text-align: right; }
</style>
</head>
<body>
<div id="param">
<%= text_field_tag :left %>
<%= select_tag :operator,    '<option>+</option><option>-</option><option>*</option><option>/</option>' %>
<%= text_field_tag :right %>
<%= observe_field :right, :update => :result,:url => 'calc', :frequency => 0.2, :submit => :param %>
<%= link_to_remote '=', :update => :result_list, :position => :top, :url => 'update', :submit => :param %>
<span id="result"></span>
</div>
<div id="result_list">
</div>
</body>
</html>

_result.rhtml

<%=h @result %>

_update_result.rhtml

<div><%=h @result %></div>