views:

177

answers:

2

hello!

has somebody from you followed this tutorial? link text

I really don´t now why, but I got following fault, when I went through the tutorial word by word:

@album[photo_attributes]‘ is not allowed as an instance variable name

somebody an idea why?

A: 

Hello,

Edited The problem may be from the fact that the variable 'photo' may be nil.

Replace the

<% fields_for ... %>
 ...
<% end %>

block with

<%= photo.inspect.to_s %>

and see if this is the case.

Edited

Try a monkey patch: instead of photo, put Photo.new

<% fields_for 'album[photo_attributes][]', Photo.new do |u| %>
Vlad Zloteanu
@vlad.zloteanu:thanks for your answer. i tried it, but same fault happened..i really don´t check it, because i went through the whole tutorial step by step a few times, and every time same fault..do you have another idea what could be wrong in my code?
@mattherick: Where exactly you get this error? When you try to render the views or when you submit the form? Please also paste a snippet with the code (and the line) where you get the error.
Vlad Zloteanu
@vlad.zloteanu: I become the error, when I try to render the views. I have a new.html.erb and into this i render a _form.html.erb and into this I render _photo.html.erb. This file contains following code: <div class="photo"> <% fields_for 'album[photo_attributes][]', photo do |u| %> <p> <%= u.label :Photo %><br /> <%= u.file_field :data, :index => nil %> <%= link_to_function "Remove", "remove_field($(this), ('.photo'))" %> </p> <% end %> </div> and I get the error at line 2 from the of the _photo.html.erbthis line contains:<% fields_for 'album[photo_attributes][]', photo do |u| %>
OK.Please try it as i told you (without the 'photo'), make sure you don't have any cached classes (make sure that the edited code is actually the code that is run), and then paste again the error and the line that generated it.
Vlad Zloteanu
tried, same error..`@album[photo_attributes]' is not allowed as an instance variable nameNameError in Albums#newShowing vendor/extensions/cms/app/views/albums/_photo.html.erb where line #2 raised: 1: <div class="photo">2: <% fields_for 'album[photo_attributes][]' do |u| %>3: <p>4: <%= u.label :Photo%><br />5: <%= u.file_field :data, :index => nil %>
my new function in albums_controller# new album def new @album = Album.new 1.upto(2) { @album.photos.build } respond_to do |format| format.html # new.html.erb format.xml { render :xml => @album } end end
OK, got it. You have an issue because the variable 'photo' is nil. :) instead of <% fields_for ... %> ... <% end %>, just place a <%= photo.inspect %> and you will see ;)
Vlad Zloteanu
ok, thanks vlad.zloteanuif i do this, i get no error, but i just have links in the view which look like following one:#Removeand no option to insert new files for uploading..
how I can get this two lines of code in the photo.inspect blog?<%= u.label :Photo %><br /><%= u.file_field :data, :index => nil %>because they are missing..
ok, since i do not have more of your code, i can not determine why your photo variable gets nil. Try a monkey patch: instead of photo, put Photo.new :)<% fields_for 'album[photo_attributes][]', Photo.new do |u| %>
Vlad Zloteanu
tried, doesn´t work..i don´t check why photo is nil, but i will try few hours more, and hopefully it will work...:)but thanks vlad
i don´t check it...somebody who worked through the same tutorial has an idea?
ok, i completely refactored my structure..now it works :)
A: 

Hi mattherick,

I had same sort of trouble, and I find this topic link text

I think it will solve your problem

MrJack
hi mr. jack!thanks, but I have already solved my problem.mattherick