This is probably a silly question, but I'm following a videocast about Rails, right now I'm working with a controller a 2 views. I'm having a minor issue with a parameter.
View one has something like this:
<%= link_to("link", {:action => 'hello', :id => 1, :page => 11}) %>
My controller is supposed to take params[:page] then parse it as an int (.to_i) then return the value in the form of an instance variable, like this:
@page = params[:page].to_i
My second view has something like this:
correct output: <%= params['page'].to_i + 1 %> <br>
// this works alright, but I'm not using the controller
controller output: <%= @page + 1 %> <br>
// this throws an exception, 'nil value' | this works in the videocast
incorrect output: <%= @page.to_i + 1 %> <br>
// @pa开发者_运维技巧ge.to_i returns a value of 0, so it's 1 total
It's something silly but I don't want to start off with the left foot on this.
Thanks, Leo
PD: I'm using WEBrick, Ruby 192 and Rails 3 (on Windows).
Kind of an odd error since it worked for me. Are you setting @page in your home action? Only way I could see that error happening is that you are calling an action that is rendering a page where @page is not being set. Can you paste your home action?
精彩评论