好的,所以基本上我正在做一个 Web 应用程序,我希望用户为一个名为 @radius 的常量输入一个给定值,我稍后将使用它。
假设我在名为“business/index.html.erb”的视图中有以下代码
<%= form_tag root_path do %>
<%= number_field_tag :radius %>
<%= submit_tag "add" %>
<% end %>
然后我在 index 操作下的 business_controller 中有以下代码:
@radius= params[:radius] || @radius || 1
我的路线文件:
root :to => 'business#index'
post "business/index"
基本上,视图看起来不错,但是当我实际更改半径并提交它时,它仍然默认为 1,好像 params[:radius] 为 nil。关于我所缺少的任何想法?我敢肯定这是相当初级的。
编辑:
这是日志文件的一部分,我相信这是我被要求的
Started POST "/" for 127.0.0.1 at 2013-06-20 02:00:31 -0430
Processing by BusinessController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CaD40O9gAedbeDepeDHtrMNNWzD/uBznHZ30ZGy+c6Q=", "radius"=>"2", "commit"=>"add"}
[1m[35mBusiness Load (18.0ms)[0m SELECT businesses.*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((10.5083644 - businesses.latitude) * PI() / 180 / 2), 2) + COS(10.5083644 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((-66.83536699999999 - businesses.longitude) * PI() / 180 / 2), 2))) AS distance, CAST(DEGREES(ATAN2( RADIANS(businesses.longitude - -66.83536699999999), RADIANS(businesses.latitude - 10.5083644))) + 360 AS decimal) % 360 AS bearing, ( businesses.reviews_count / (nullif(businesses.reviews_count + MAX(businesses.reviews_count) OVER(),0)) ) * businesses.rating + (MAX(businesses.reviews_count) OVER() / (nullif(businesses.reviews_count+MAX(businesses.reviews_count) OVER(),0))) * AVG(businesses.rating) OVER() as ranking FROM "businesses" WHERE (businesses.latitude BETWEEN 10.490377967881624 AND 10.526350832118375 AND businesses.longitude BETWEEN -66.85366024099285 AND -66.81707375900713 AND 6371.0 * 2 * ASIN(SQRT(POWER(SIN((10.5083644 - businesses.latitude) * PI() / 180 / 2), 2) + COS(10.5083644 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((-66.83536699999999 - businesses.longitude) * PI() / 180 / 2), 2))) <= '2') GROUP BY businesses.id ORDER BY distance ASC, ranking DESC
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/gmaps4rails-1.5.6/app/views/gmaps4rails/_gmaps4rails.html.erb (1.0ms)