渲染部分表单时路由错误 [英] Routing error in rendering partial form

查看:136
本文介绍了渲染部分表单时路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个项目,其中有一个类 online_score ,其中一个属性名为 url of online_score_url 对象。我现在做的是以下内容。代码可能有点肮脏,因为我不断尝试新事物,但只要我得到它的工作,我会清理它。
views / online_score / new:

 < h3>连结:< / h3> 
< div class =urlInput>
<%f.fields_for:url do | f | %GT;
< 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_fieldsremove,f%>
< / div>
<%end%>
<%= add_url_link添加另一个链接,f%> #works罚款,如果我删除这条规则
< / div>

views / online_score / _online_score_url_fields:

 <%= f.fields_for:item do | b | %GT; 
< 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_fieldsremove,b%>
< / div>
<%end%>

现在我的问题是我希望能够为动态添加输入, online_score_url 我试图用JQuery做的对象。我尝试通过渲染部分内容来实现这一点:$ b​​ $ b 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}

页面<< %{
$('。links')。append(#{escape_javascript online_score_url});
}
end
end

现在的问题是它给出以下错误:


ActionController :: RoutingError in Online_scores#new



显示/home/kvhooreb/jenna_vopro/score/app/views/online_scores/new.html.erb其中line>#22 raise:



没有路线匹配{:action = >show,::controller =>online_scores,:locale =>:en}
提取的源代码(在第22行左右):

19:
20:<%#=渲染online_score_url_fields,:f => f%>
21:<%end%>
22:<%= add_url_linkAdd Another link ,f%>
23:
24:

25:
Rails.root:/ home / kvhooreb /​​ jenna_vopro / score


应用程序跟踪|框架跟踪|完整跟踪
app / helpers / online_scores_helper.rb:20:在 block in add_url_link'
app / helpers / online_scores_helper.rb:15:在
add_url_link '
app / views / online_scores / new.html.erb:22:在块中> _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'
请求

参数:

{ piece=>1,
locale=>en}


是什么原因导致的有人有想法吗?
感谢您的时间。

解决方案

根据您提供的信息,我将假设问题在 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 来呈现路线。没有它,你会得到错误信息:

 没有路线匹配{:action =>show,:controller =>online_scores,:locale =>:en}提取的源代码(在第22行左右):


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:inadd_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.

解决方案

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):"

这篇关于渲染部分表单时路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆