渲染部分表单时出现路由错误

发布于 2024-11-02 05:18:45 字数 2643 浏览 3 评论 0原文

我正在创建一个项目,其中有一个类 online_score ,该类的属性之一是一个名为 urlonline_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:inadd_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_urlobjects 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/score

Application Trace | Framework Trace | Full Trace
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 block 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'
Request

Parameters:

{"piece"=>"1",
"locale"=>"en"}

Now I have no clue what causes this. Does anyone have an idea?
Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2024-11-09 05:18:45

根据您提供的信息,我假设问题出在 app/helpers/online_scores_helper.rb 中,特别是这一行:

$('.links').append("#{ escape_javascript online_score_url }");

如果您为 online_scores 定义了标准资源,则要么引用特定的在线分数记录 online_score_url(online_score.id),要么引用在线分数列表 online_score_urls

online_score_url 是单数,通常需要一个 id 来呈现路线。如果没有它,您将收到错误消息:

"No route matches {:action=>"show", :controller=>"online_scores", :locale=>:en} Extracted source (around line #22):"

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:

$('.links').append("#{ escape_javascript online_score_url }");

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 scores online_score_urls.

online_score_url, being singular, normally would expect an id in order to render the route. Without it, you would get the error message:

"No route matches {:action=>"show", :controller=>"online_scores", :locale=>:en} Extracted source (around line #22):"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文