0

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.

2
  • Which line is line 15 of app/helpers/online_scores_helper.rb ? I am betting that it's the one with "escape_javascript online_score_url" Commented Apr 16, 2011 at 8:32
  • What does your route definition look like for your online_scores resource? Have you defined it in routes.rb? Commented Apr 16, 2011 at 8:34

1 Answer 1

2

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):"
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, thank you. Your comment wast the solution, but It made mee see my mistake. online_score_url is a variable which should be defined here: instrument_online_score = render :partial => "online_score_url_fields", :locals => {:f => f, :item => item} so that should be: online_score_url = render :partial => "online_score_url_fields", :locals => {:f => f, :item => item}. I copy pasted some code apparently and I forgot to edit that. It doesn't work completely yet, but at least it doesn't give an error anymore so I can start looking into that again. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.