English 中文(简体)
以数组方式传递到窗体_for() 和链接_ to()
原标题:Passing in an array into form_for() and link_to()

我在读《行动中的铁路3》。这本书构建了一组项目,其中 has_many:tickets 和一系列入场券,其中 属于_to:project 。路径.rb文件看起来像这样:

    resources :projects do
      resources :tickets
    end

现在创建罚单的表格以类似阵列的形式排列 :

    <%= form_for [@project, @ticket] do |f| %>

在售票展示.html.erb页面上,有些链接看起来是这样的:

    <%= link_to "Edit Ticket", [:edit, @project, @ticket] %>
    <%= link_to "Delete Ticket", [@project, @ticket], :method => :delete,
    :confirm => "Are you sure you want to delete this ticket?" %>

现在,我不明白为什么两个对象的阵列需要被传递成形式_for()和链接_to()。此外,为什么“编辑票”需要和:编辑符号,而“删除票”不需要:销毁符号。

thanks, mike

最佳回答

从含有两种资源标识的 URL 中嵌入资源路径, 在此情况下类似 : < code>/ project /1/tickets/ 10 。 要生成此 URL, 我们需要知道工程和票的代号, 因此这两个对象都需要通过 。

编辑 URL 更进一步, 并添加一个动作关键字 - / project /1/tickets/10/edit , 所以我们需要在此动作中通过 。

然而,铁路中的一种再生的破坏路线使用HTTP方法DELETE, 而不是一个动作关键词, 所以用来摧毁您的票的 URL 实际上是 / project /1/tickets/10 ; 只是使用 DELETE 请求而不是 Get。

详情请见 rel=“noreferrer”>Rails Routing from the outside

问题回答

暂无回答




相关问题
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: ...

热门标签