渲染部分表单时出现路由错误
我正在创建一个项目,其中有一个类 online_score
,该类的属性之一是一个名为 url
的 online_score_url
对象数组。到目前为止我所做的如下。代码可能有点脏,因为我不断尝试新事物,但一旦我让它工作,我就会清理它。 views/online_score/new:
<h3>Links: </h3>
<div class="urlInput">
<%f.fields_for :url do |f| %>
<div class="inputset">
<%= f.label :url %> <%= f.url_field :url, :value => "http://www.google.be"%>
<%= f.label :description %> <%= f.text_field :description %>
<%= link_to_remove_fields "remove", f %>
</div>
<%end %>
<%= add_url_link "Add Another link", f %> #works fine if I remove this rule
</div>
views/online_score/_online_score_url_fields:
<%= f.fields_for :item do |b| %>
<div class="inputset">
<%= b.label :url %> <%= b.url_field :url, :value => "http://www.google.be"%>
<%= b.label :description %> <%#= b.text_field :description %>
<%= link_to_remove_fields "remove", b %>
</div>
<% end %>
我现在的问题是我希望能够为我尝试使用 JQuery 执行的 online_score_url
对象动态添加输入。我尝试通过像这样渲染部分来做到这一点: helpers/online_scores_helper.rb:
def add_url_link(name, f)
link_to_function name do |page|
item = OnlineScoreUrl.new("", "")
instrument_online_score = render :partial => "online_score_url_fields", :locals => {:f => f, :item => item}
page << %{
$('.links').append("#{ escape_javascript online_score_url }");
}
end
end
现在的问题是它给出以下错误:
Online_scores#new 中的 ActionController::RoutingError
显示 /home/kvhooreb/jenna_vopro/score/app/views/online_scores/new.html.erb 其中行 >#22 引发:
没有路线匹配 {:action=>"show", :controller=>"online_scores", :locale=>:en} 提取的源代码(第 22 行附近):
19: 20: <%#= 渲染“online_score_url_fields”, :f => f%> 21:<%结束%> 22: <%= add_url_link "添加另一个链接", f %> 23: 24:
25: Rails.root:/home/kvhooreb/jenna_vopro/score应用程序跟踪|框架跟踪 |完整追踪 app/helpers/online_scores_helper.rb:20:in
block in add_url_link' app/helpers/online_scores_helper.rb:15:in
add_url_link' app/views/online_scores/new.html.erb:22:in块 >_app_views_online_scores_new_html_erb__1492671958001855269_22836400_2958786211230549542' app/views/online_scores/new.html.erb:3:in >
_app_views_online_scores_new_html_erb__1492671958001855269_22836400_2958786211230549542' 请求参数:
{"件"=>"1", “区域设置”=>“en”}
现在我不知道是什么原因造成的。有人有想法吗? 感谢您抽出时间。
I'm making a project for which I have a class online_score
which has as one of its attributes an array called url
of online_score_url
objects. What I did up to now is the following. The code might be a little dirty because I'm constantly trying new things, but as soon as I get it working, I'll clean it up.
views/online_score/new:
<h3>Links: </h3>
<div class="urlInput">
<%f.fields_for :url do |f| %>
<div class="inputset">
<%= f.label :url %> <%= f.url_field :url, :value => "http://www.google.be"%>
<%= f.label :description %> <%= f.text_field :description %>
<%= link_to_remove_fields "remove", f %>
</div>
<%end %>
<%= add_url_link "Add Another link", f %> #works fine if I remove this rule
</div>
views/online_score/_online_score_url_fields:
<%= f.fields_for :item do |b| %>
<div class="inputset">
<%= b.label :url %> <%= b.url_field :url, :value => "http://www.google.be"%>
<%= b.label :description %> <%#= b.text_field :description %>
<%= link_to_remove_fields "remove", b %>
</div>
<% end %>
My problem is now that I want to be able to dynamically add inputs for online_score_url
objects which I try to do with JQuery. I try to do this by rendering the partial like so:
helpers/online_scores_helper.rb:
def add_url_link(name, f)
link_to_function name do |page|
item = OnlineScoreUrl.new("", "")
instrument_online_score = render :partial => "online_score_url_fields", :locals => {:f => f, :item => item}
page << %{
$('.links').append("#{ escape_javascript online_score_url }");
}
end
end
The problem now is that it gives the following error:
ActionController::RoutingError in Online_scores#new
Showing /home/kvhooreb/jenna_vopro/score/app/views/online_scores/new.html.erb where line >#22 raised:
No route matches {:action=>"show", :controller=>"online_scores", :locale=>:en}
Extracted source (around line #22):19:
20: <%#= render "online_score_url_fields", :f => f %>
21: <%end %>
22: <%= add_url_link "Add Another link", f %>
23:
24:
25:
Rails.root: /home/kvhooreb/jenna_vopro/scoreApplication Trace | Framework Trace | Full Trace
app/helpers/online_scores_helper.rb:20:inblock in add_url_link'
add_url_link'
app/helpers/online_scores_helper.rb:15:in
app/views/online_scores/new.html.erb:22:inblock in >_app_views_online_scores_new_html_erb__1492671958001855269_22836400_2958786211230549542'
_app_views_online_scores_new_html_erb__1492671958001855269_22836400_2958786211230549542'
app/views/online_scores/new.html.erb:3:in >
RequestParameters:
{"piece"=>"1",
"locale"=>"en"}
Now I have no clue what causes this. Does anyone have an idea?
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您提供的信息,我假设问题出在
app/helpers/online_scores_helper.rb
中,特别是这一行:如果您为 online_scores 定义了标准资源,则要么引用特定的在线分数记录
online_score_url(online_score.id)
,要么引用在线分数列表online_score_urls
。online_score_url
是单数,通常需要一个id
来呈现路线。如果没有它,您将收到错误消息:Based off the information you've provided, I am going to assume the problem is in
app/helpers/online_scores_helper.rb
, specifically, this line:If you've defined a standard resource for online_scores, you either are referring to a specific online score record
online_score_url(online_score.id)
, or referring to the list of online scoresonline_score_urls
.online_score_url
, being singular, normally would expect anid
in order to render the route. Without it, you would get the error message: