开发者

find method can't accept params[:id]

def admission2
  puts params[:id]
  @student = Student.find(params[:id])
  @guardian = Guardian.new params[:guardian]
  if request.post? and @guardian.save
    redirect_to :controller => "student", :action => "admission2", :id => @student.id
  end
end

In given code, find method throws an exception saying that

  Couldn't find Student without an ID

but the output of puts statement shows that params[:id] contains a va开发者_开发知识库lue. I've made sure that the record for given id field always exist in database.

When I manually put a number as find methods parameter, it worked so I guess find is unable accept params[:id] here, is there any other way of doing it?

I'm using rails 2.3.5


That's pretty odd. Does it make any difference if you do

@student = Student.find params[:id].to_i


Here's my old routes.rb file:

map.connect ':controller/:action'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id/:id2'
map.connect ':controller/:action/:id.:format'

I just removed map.connect ':controller/:action' from it and now everything is working perfetctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜