Hi all,
I have 2 models with a standard 1 to many relationship. I''m also using
REST on the two models and have added the appropriate code to the
routes.rb file.
scorecard.rb:
class Scorecard < ActiveRecord::Base
has_many :attributes
end
attribute.rb:
class Attribute < ActiveRecord::Base
belongs_to :scorecard
end
routes.rb:
map.resources :scorecards do |scorecard|
scorecard.resources :attributes
end
My problem is that I want to show a single scorecard with all it''s
attributes. I then want to display a "New attribute" link to add a
new
attribute to the current scorecard.
scorecards/show.rhtml:
<%= label_for("scorecard") %>
<%=h @scorecard.name %><br />
<%= label_for("template") %>
<%=h @scorecard.template %>
<b>Attributes:</b>
<table>
<% for attribute in @scorecard.attributes %>
<tr>
<td><%=h attribute.name %></td>
<td><%=h attribute.weight %></td>
</tr>
<% end %>
</table>
<%= link_to "New Attribute", new_attribute_path(@scorecard) %>
However I get the message for line 17 (last line) when I try to view
this page,
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.to_sym
I have tried checking against various REST and Rails books and articles,
and I thought I had used the correct syntax for creating a link to a new
attribute from this scorecard.
Any help on this would be greatly appreciated.
Thanks,
Matthew
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi all,
I have 2 models with a standard 1 to many relationship. I''m also
using
REST on the two models and have added the appropriate code to the
routes.rb file.
# scorecard.rb:
class Scorecard < ActiveRecord::Base
has_many :attributes
end
# attribute.rb:
class Attribute < ActiveRecord::Base
belongs_to :scorecard
end
# routes.rb:
map.resources :scorecards do |scorecard|
scorecard.resources :attributes
end
My problem is that I want to show a single scorecard with all it''s
attributes. I then want to display a "New attribute" link to add a
new
attribute to the current scorecard.
# scorecards/show.rhtml:
<%= label_for("scorecard") %>
<%=h @scorecard.name %><br />
<%= label_for("template") %>
<%=h @scorecard.template %>
<b>Attributes:</b>
<table>
<% for attribute in @scorecard.attributes %>
<tr>
<td><%=h attribute.name %></td>
<td><%=h attribute.weight %></td>
</tr>
<% end %>
</table>
<%= link_to "New Attribute", new_attribute_path(@scorecard) %>
However I get the message for line 17 (last line) when I try to view
this page,
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.to_sym
I have tried checking against various REST and Rails books and
articles,
and I thought I had used the correct syntax for creating a link to a
new
attribute from this scorecard.
Any help on this would be greatly appreciated.
Thanks,
Matthew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I think you may need to rename your Attribute model. ActiveRecord objects already have an instance variable named "attributes" which holds the attributes for the given model instance. The Scorecard''s has_many :attributes collection and the pre-existing attributes hash are probably colliding. -John On Jun 19, 7:19 am, Matthew Lang <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > I have 2 models with a standard 1 to many relationship. I''m also using > REST on the two models and have added the appropriate code to the > routes.rb file. > > scorecard.rb: > class Scorecard < ActiveRecord::Base > has_many :attributes > end > > attribute.rb: > class Attribute < ActiveRecord::Base > belongs_to :scorecard > end > > routes.rb: > map.resources :scorecards do |scorecard| > scorecard.resources :attributes > end > > My problem is that I want to show a single scorecard with all it''s > attributes. I then want to display a "New attribute" link to add a new > attribute to the current scorecard. > > scorecards/show.rhtml: > <%= label_for("scorecard") %> > <%=h @scorecard.name %><br /> > > <%= label_for("template") %> > <%=h @scorecard.template %> > > <b>Attributes:</b> > <table> > <% for attribute in @scorecard.attributes %> > <tr> > <td><%=h attribute.name %></td> > <td><%=h attribute.weight %></td> > </tr> > <% end %> > </table> > <%= link_to "New Attribute", new_attribute_path(@scorecard) %> > > However I get the message for line 17 (last line) when I try to view > this page, > > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.to_sym > > I have tried checking against various REST and Rails books and articles, > and I thought I had used the correct syntax for creating a link to a new > attribute from this scorecard. > > Any help on this would be greatly appreciated. > > Thanks, > > Matthew > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Problem solved!
In the routes.rb file I had the following
map.resources :scorecards do |scorecard|
scorecard.resources :perspectives
end
map.resources :perspectives do |perspective|
perspective.resources: scores
end
when I should have had
map.resources :scorecards do |scorecard|
scorecard.resources :perspectives do |perspective|
perspective.resources :score
end
end
Thanks,
Matthew
On Jun 20, 8:25 pm, jparker
<johncpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I think you may need to rename your Attribute model. ActiveRecord
> objects already have an instance variable named "attributes"
which
> holds the attributes for the given model instance. The Scorecard''s
> has_many :attributes collection and the pre-existing attributes hash
> are probably colliding.
>
> -John
>
> On Jun 19, 7:19 am, Matthew Lang
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> wrote:
>
> > Hi all,
>
> > I have 2 models with a standard 1 to many relationship. I''m
also using
> > REST on the two models and have added the appropriate code to the
> > routes.rb file.
>
> > scorecard.rb:
> > class Scorecard < ActiveRecord::Base
> > has_many :attributes
> > end
>
> > attribute.rb:
> > class Attribute < ActiveRecord::Base
> > belongs_to :scorecard
> > end
>
> > routes.rb:
> > map.resources :scorecards do |scorecard|
> > scorecard.resources :attributes
> > end
>
> > My problem is that I want to show a single scorecard with all
it''s
> > attributes. I then want to display a "New attribute" link
to add a new
> > attribute to the current scorecard.
>
> > scorecards/show.rhtml:
> > <%= label_for("scorecard") %>
> > <%=h @scorecard.name %><br />
>
> > <%= label_for("template") %>
> > <%=h @scorecard.template %>
>
> > <b>Attributes:</b>
> > <table>
> > <% for attribute in @scorecard.attributes %>
> > <tr>
> > <td><%=h attribute.name %></td>
> > <td><%=h attribute.weight %></td>
> > </tr>
> > <% end %>
> > </table>
> > <%= link_to "New Attribute",
new_attribute_path(@scorecard) %>
>
> > However I get the message for line 17 (last line) when I try to view
> > this page,
>
> > You have a nil object when you didn''t expect it!
> > The error occurred while evaluating nil.to_sym
>
> > I have tried checking against various REST and Rails books and
articles,
> > and I thought I had used the correct syntax for creating a link to a
new
> > attribute from this scorecard.
>
> > Any help on this would be greatly appreciated.
>
> > Thanks,
>
> > Matthew
>
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---