Hiya,
I have the following models:
user
user_bookmarks
bookmarks
It is a standard "has_many :through" relationship. Here is the issue
though, I am using link_to_remote to add the bookmark for that
wonderful ajax feeling.
<%= link_to_remote ''Bookmark!'', :url =>
user_bookmarks_path
(current_user, @item) %>
I am using TechnoWeenies Restful_Authentication plugin (hence the
current_user object), but I can''t seem to get this to work. This
*should* be POSTing via AJAX to UserBookmarks#create but I can''t even
get that far.
Here is the error:
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.to_sym
Extracted source (around line #12):
9: <% if logged_in? %>
10:
11: <p class="user_bookmark_<%= @item.id %>">
12: <%= link_to_remote ''Bookmark!'', :url =>
user_bookmarks_path
(current_user, @item) %>
13: </p>
14:
15: <% end %>
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/
active_support/core_ext/hash/keys.rb:27:in `symbolize_keys''
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/
active_record/base.rb:1941:in `inject''
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/
active_support/core_ext/hash/keys.rb:26:in `each''
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/
active_support/core_ext/hash/keys.rb:26:in `inject''
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/
active_support/core_ext/hash/keys.rb:26:in `symbolize_keys''
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
helpers/url_helper.rb:21:in `url_for''
(eval):19:in `user_bookmarks_path''
#{RAILS_ROOT}/app/views/items/show.rhtml:12:in
`_run_rhtml_47app47views47items47show46rhtml''
app/controllers/items_controller.rb:20:in `show''
app/controllers/items_controller.rb:20:in `show''
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------
If anyone could help out, i''d appreciate it.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On 22-Feb-07, at 12:35 PM, chris loper wrote:> > Hiya, > > I have the following models: > > user > user_bookmarks > bookmarks > > It is a standard "has_many :through" relationship. Here is the issue > though, I am using link_to_remote to add the bookmark for that > wonderful ajax feeling. > > <%= link_to_remote ''Bookmark!'', :url => user_bookmarks_path > (current_user, @item) %> > >> could help out, i''d appreciate it.Hey Chris; I''ve found that keying the params is needed (might just be for nested resources, as I''m still wrestling a bit with the helpers), try : user_bookmarks_path(:user => current_user, :bookmark => @item) Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Feb 22, 2007, at 9:43 AM, Jodi Showers wrote:> > Hey Chris; > > I''ve found that keying the params is needed (might just be for nested > resources, as I''m still wrestling a bit with the helpers), > > try : user_bookmarks_path(:user => current_user, :bookmark => @item)Jodi, I tried this but got the following error: user_bookmarks_url failed to generate from {:item=>"1", :action=>"index", :user=>"1", :controller=>"user_bookmarks" }, expected: {:action=>"index", :controller=>"user_bookmarks"}, diff: {:item=>"1", :user=>"1"} --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 22-Feb-07, at 12:59 PM, chris loper wrote:> > On Feb 22, 2007, at 9:43 AM, Jodi Showers wrote: >> >> Hey Chris; >> >> I''ve found that keying the params is needed (might just be for nested >> resources, as I''m still wrestling a bit with the helpers), >> >> try : user_bookmarks_path(:user => current_user, :bookmark => @item) > > Jodi, > > I tried this but got the following error: > > user_bookmarks_url failed to generate from > {:item=>"1", :action=>"index", :user=>"1", :controller=>"user_bookmark > s" > }, expected: {:action=>"index", :controller=>"user_bookmarks"}, diff: > {:item=>"1", :user=>"1"}Chris, can you please post the applicable route? Jodi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jodi:
map.resources :users do |user|
user.resources :user_bookmarks
end
Thanks.
On Feb 22, 2007, at 10:17 AM, Jodi Showers wrote:
>
>
> On 22-Feb-07, at 12:59 PM, chris loper wrote:
>
>>
>> On Feb 22, 2007, at 9:43 AM, Jodi Showers wrote:
>>>
>>> Hey Chris;
>>>
>>> I''ve found that keying the params is needed (might just be
for
>>> nested
>>> resources, as I''m still wrestling a bit with the helpers),
>>>
>>> try : user_bookmarks_path(:user => current_user, :bookmark =>
@item)
>>
>> Jodi,
>>
>> I tried this but got the following error:
>>
>> user_bookmarks_url failed to generate from
>> {:item=>"1", :action=>"index",
:user=>"1", :controller=>"user_bookmar
>> k
>> s"
>> }, expected: {:action=>"index",
:controller=>"user_bookmarks"}, diff:
>> {:item=>"1", :user=>"1"}
>
> Chris, can you please post the applicable route?
>
> Jodi
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
ok chris, this seems to work on my end: <%= link_to_remote ''Bookmark!'', :url => user_bookmarks_path(:user_id => current_user, :bookmark_id => @item) %> the _id''s have it! Jodi On Feb 22, 9:33 pm, chris loper <clo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> jodi: > > map.resources :users do |user| > user.resources :user_bookmarks > end > > Thanks. > > On Feb 22, 2007, at 10:17 AM, Jodi Showers wrote: > > > > > On 22-Feb-07, at 12:59 PM, chris loper wrote: > > >> On Feb 22, 2007, at 9:43 AM, Jodi Showers wrote: > > >>> Hey Chris; > > >>> I''ve found that keying the params is needed (might just be for > >>> nested > >>> resources, as I''m still wrestling a bit with the helpers), > > >>> try : user_bookmarks_path(:user => current_user, :bookmark => @item) > > >> Jodi, > > >> I tried this but got the following error: > > >> user_bookmarks_url failed to generate from > >> {:item=>"1", :action=>"index", :user=>"1", :controller=>"user_bookmar > >> k > >> s" > >> }, expected: {:action=>"index", :controller=>"user_bookmarks"}, diff: > >> {:item=>"1", :user=>"1"} > > > Chris, can you please post the applicable route? > > > Jodi--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jodi Showers wrote:> ok chris, this seems to work on my end: > > <%= link_to_remote ''Bookmark!'', :url => user_bookmarks_path(:user_id > => current_user, :bookmark_id => @item) %> > > the _id''s have it! > > JodiHmm, surely the plural path shouldn''t need a bookmark ID ? -- 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 -~----------~----~----~----~------~----~------~--~---
On 23-Feb-07, at 9:23 AM, Alan Francis wrote:> > Jodi Showers wrote: >> ok chris, this seems to work on my end: >> >> <%= link_to_remote ''Bookmark!'', :url => user_bookmarks_path(:user_id >> => current_user, :bookmark_id => @item) %> >> >> the _id''s have it! >> >> Jodi > > Hmm, surely the plural path shouldn''t need a bookmark ID ?the resource user_bookmarks is an intersection model - so both sides of the intersection are required. Jodi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what I meant to say Alan was that the controller logic requires the bookmark_id to create the join. It''s not needed (as you were likely saying) to generate the url. Jodi On Feb 23, 9:40 am, Jodi Showers <j...-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:> On 23-Feb-07, at 9:23 AM, Alan Francis wrote: > > > > > Jodi Showers wrote: > >> ok chris, this seems to work on my end: > > >> <%= link_to_remote ''Bookmark!'', :url => user_bookmarks_path(:user_id > >> => current_user, :bookmark_id => @item) %> > > >> the _id''s have it! > > >> Jodi > > > Hmm, surely the plural path shouldn''t need a bookmark ID ? > > the resource user_bookmarks is an intersection model - so both sides > of the intersection are required. > > Jodi--~--~---------~--~----~------------~-------~--~----~ 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 thought that the plural version of the helper did NOT require an id
and the singular version did. The plural version of the restful
routing helper methods are for linking to collections of objects. The
singular version is for linking to a specific object and thus requires
the id for it.
More information on routes and resources is available here:
http://caboo.se/doc/classes/ActionController/Resources.html
Note especially the use of the singular and plural routing helpers and
their respective required params:
# GET messages_url
# GET message_url(:id => 1)
hth,
jacqui
On Feb 23, 6:46 am, "Jodi"
<j...-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org>
wrote:> what I meant to say Alan was that the controller logic requires the
> bookmark_id to create the join.
>
> It''s not needed (as you were likely saying) to generate the url.
>
> Jodi
>
> On Feb 23, 9:40 am, Jodi Showers
<j...-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:
>
> > On 23-Feb-07, at 9:23 AM, Alan Francis wrote:
>
> > > Jodi Showers wrote:
> > >> ok chris, this seems to work on my end:
>
> > >> <%= link_to_remote ''Bookmark!'', :url
=> user_bookmarks_path(:user_id
> > >> => current_user, :bookmark_id => @item) %>
>
> > >> the _id''s have it!
>
> > >> Jodi
>
> > > Hmm, surely the plural path shouldn''t need a bookmark ID
?
>
> > the resource user_bookmarks is an intersection model - so both sides
> > of the intersection are required.
>
> > Jodi
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Jacqui,
first of all I''m still getting this stuff straight, but this is how I
understand this.
First this is a nested resource, so the parent id is required. And
secondly this is a create, so we''re dealing with a POST.
given the route definition:
map.resources :users do |user|
user.resources :user_bookmarks
end
to create a user_bookmark (the object of this exercise) we use the
plural helper to add to the collection.
so user_bookmarks_url
but since user_bookmarks is nested, we must supply the parent
resource id (user).
user_bookmarks_url(:user_id => current_user)
if we were just creating a user(a non-nested resource) then the
helper call would look like:
users_url
I''m I daffy? btw, the above works well in a test app modeled on
Chris'' supplied routes and model definitions.
Jodi
On 23-Feb-07, at 11:15 AM, jacqui wrote:
>
> I thought that the plural version of the helper did NOT require an id
> and the singular version did. The plural version of the restful
> routing helper methods are for linking to collections of objects. The
> singular version is for linking to a specific object and thus requires
> the id for it.
>
> More information on routes and resources is available here:
>
> http://caboo.se/doc/classes/ActionController/Resources.html
>
> Note especially the use of the singular and plural routing helpers and
> their respective required params:
> # GET messages_url
> # GET message_url(:id => 1)
>
> hth,
> jacqui
>
>
> On Feb 23, 6:46 am, "Jodi"
<j...-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:
>> what I meant to say Alan was that the controller logic requires the
>> bookmark_id to create the join.
>>
>> It''s not needed (as you were likely saying) to generate the
url.
>>
>> Jodi
>>
>> On Feb 23, 9:40 am, Jodi Showers
<j...-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:
>>
>>> On 23-Feb-07, at 9:23 AM, Alan Francis wrote:
>>
>>>> Jodi Showers wrote:
>>>>> ok chris, this seems to work on my end:
>>
>>>>> <%= link_to_remote ''Bookmark!'', :url
=> user_bookmarks_path
>>>>> (:user_id
>>>>> => current_user, :bookmark_id => @item) %>
>>
>>>>> the _id''s have it!
>>
>>>>> Jodi
>>
>>>> Hmm, surely the plural path shouldn''t need a bookmark
ID ?
>>
>>> the resource user_bookmarks is an intersection model - so both
sides
>>> of the intersection are required.
>>
>>> Jodi
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---