English 中文(简体)
如何用铁路3.2.3以原始提交形式处理参数
原标题:how to handle parameters in a raw submit form in rails 3.2.3

我如何处理从原始 HTML 形式传入的参数?

载于/views/feeders/index.html.erb:

<form action="/feeders/extract/" method="post" accept-charset="utf-8">
    <input type="text" name="url" value="" id="url">    
    <p><input type="submit" value="submit"></p>
</form>

/控制器/控制器/控制器_控制器.rb

class FeedersController < ApplicationController
  def index
    @url=params[:url]
  end

  def show

  end

  def extract
    @url=params[:url]
    redirect_to :controller =>  feeders , :action =>  show 
  end
end

在.rb路线中:

 root :to =>  feeders#index 
  match  /feeders/extract/:url  =>  feeders#extract , :via => :post
  match  /feeders/show/  =>  feeders#show 

我不断得到

Routing Error

No route matches [POST] "/feeders/extract"
最佳回答

点 # 1

将路径设置为

post "feeders/extract" => "feeders#extract"

your route match /feeders/extract/:url => feeders#extract , :via => :post

允许像

POST /feeders/extract/somevalue => params[:url] =>  somevalue 
POST /feeders/extract/123       => params[:url] =>  123 

尝试“ rake 路线” 来了解更多

点2: 在您遵循上面 # 1 之后

我试图从你的评论中理解你的需求,而你需要的是如下:

在您的路径中.rb

post "feeders/extract" => "feeders#show"
match  /feeders/show/  =>  feeders#show 

然后也许你不需要在 Feeders 主计长.rb 中进行抽取动作, 显示动作会被用参数呼叫抽取动作 [:url]

#3点 # 3( 替代到 # 2): 在您遵循上面 # 1 之后

简单的将控制器编辑为

render :show # redirect_to :controller =>  feeders , :action =>  show 

而不是转而到那里

因此,您可以使用#1,#2或#1,#3,满足您的需求。

你应该用# 1,# 2, 如果“ extract” 动作/ 过程有更大的意义, 我是指终端用户 。

希望我能理解你的想法:

问题回答

邮件请求试图点击 / feeders/ outtract/ ,但您没有匹配的路径(我看到最接近的路径是 / feeder/ outtract/:url )。

将您的路径更改为 match/ feeders/ extract/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

一旦请求被正确定位到提取动作, 您仍需要 参数[: url]





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...