The partial name (sets/3/0) is not a valid Ruby identifier -


i trying render decently-complex series of partials in app , getting following error message:

the partial name (sets/3/1) not valid ruby identifier; make sure partial name starts underscore, , followed combination of letters, numbers , underscores. 

this partial rendered generators#show action, using following code:

<% @random_partial = 'sets/' + bucket.to_s + '/' + rand(2).round.to_s %> <%= render partial: @random_partial %> 

bucket number (between 1 , 7, not that matters) , random number choose random partial in bucket. file structure looks this:

generators |--exercises     |--_cardio0.html.erb     |--_cardio1.html.erb     |--_weight0.html.erb     |--_weight1.html.erb |--sets     |--1        |--_0.html.erb        |--_1.html.erb     |--2        |--_0.html.erb        |--_1.html.erb     |--3        |--_0.html.erb        |--_1.html.erb     |--4        |--_0.html.erb        |--_1.html.erb     |--5        |--_0.html.erb        |--_1.html.erb     |--6        |--_0.html.erb        |--_1.html.erb     |--7        |--_0.html.erb        |--_1.html.erb |--new.html.erb |--show.html.erb 

finally, don't think impacts error being displayed, sample of 1 of sets partials looks like:

<% @random_cardio_1 = 'exercises/_cardio' + rand(2).round.to_s %> 5 minutes of <%= render partial: @random_cardio_1 %>  <% @random_cardio_2 = 'exercises/_cardio' + rand(2).round.to_s %> 5 minutes of <%= render partial: @random_cardio_2 %>  <% @random_cardio_3 = 'exercises/_cardio' + rand(2).round.to_s %> 5 minutes of <%= render partial: @random_cardio_3 %> 

can else figure out why error being generated or how correct code?

i tested , found out can't have partial integer name yours in rails 4. there problems in code.

first, refer partial using relative directory after app/views. add generators/ @ start of path.

second, mentioned earlier can't use integer partial name, please rename partial else. example add p integer named partials. _1.html.erb renamed _p1.html.erb.

third, not add additional _ when referring partial. 'generators/sets/' + bucket.to_s + '/' + rand(2).round.to_s ok, <% @random_cardio_3 = 'exercises/_cardio' + rand(2).round.to_s %> not ok.

so can render by,

<% @random_partial = 'generators/sets/' + bucket.to_s + '/p' + rand(2).round.to_s %> <%= render partial: @random_partial %> 

and nested partial remove _ before cardio

<% @random_cardio_3 = 'generators/exercises/cardio' + rand(2).round.to_s %> 5 minutes of <%= render partial: @random_cardio_3 %> 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -