【问题标题】:request.raw_post trying to pull data from itrequest.raw_post 试图从中提取数据
【发布时间】:2010-07-29 21:10:17
【问题描述】:
  def search_results
       @keyword = request.raw_post
       @tutors = Tutors.find(:all,:conditions => ["first_name LIKE ?", '%' + "raul" + '%'])    
  end

我试图从request.raw_post 中获取一些信息,但它给了我这个长字符串:“authenticity_token=HxxkPMpSr0kHZOVZIYbpMti217BTeUa5G2vX8zbs8ig%3D&keyword=alex&authenticity_token=HxxkPMpSr0kHZOVZIYbpMti217BTeUa5G2vX8

基本上,我只是为了得到“alex”,它说“keyword=alex”。我该怎么做?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    如果你想要这个值,我建议使用params[:keyword]

    或者,request.raw_post.split(/&/).grep(/keyword=/).first.split(/=/).last

    【讨论】:

    • 是的,这正是我所做的。
    猜你喜欢
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 2016-12-18
    • 2022-08-19
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多