I次のコードを持っており、それは私も試したRailsの - コレクションが空の場合、代替のための構文は、レンダリング
$('div').html("<%= escape_javascript (render partial: 'comments/image_comment',
collection: @image_comments || render html: "<strong>Not Found</strong>".html_safe) %>");
を働いていない私は、いくつかのために速記render @image_comments
を使用することはできません
$('div').html("<%= escape_javascript (render (partial: 'comments/image_comment',
collection: @image_comments) || render (html: "<strong>Not Found</strong>".html_safe)) %>");
この私はレールを行う際に理由理由は、私が代わりに_comments.html.erb
の_image_comments.html.erb
を命名していると私はなぜ知らない部分を使用しています。
エラー
SyntaxError (/show_comments.js.erb:4: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
[email protected]_comments || render html: "<strong>Not Found</strong>"...
... ^
/show_comments.js.erb:4: syntax error, unexpected ')', expecting keyword_end
...ot Found</strong>".html_safe));@output_buffer.safe_append='...
なって何のエラー、uが投稿できますか? – 7urkm3n
Rubyは実際には空白に敏感です。メソッド呼び出しで括弧を使用する場合は、メソッド名と開始括弧の間にスペースを入れないでください。 –
'show_comments.js.erb' - >' <%data = @image_comments?>でこれを試すことができますか? @ が見つかりません。 ""%> $( 'div').html(<%= data%>); ' – 7urkm3n