Hi Mateusz,

On Sun, Jan 22, 2012 at 11:29 AM, Mateusz W. <li...@ruby-forum.com> wrote:
...
> Now, if I add an Ajax layer over this, things seem to complicate quite a
> bit. Say, if I want to perform some kind of request using jQuery, I need
> to be able to know the appropriate path to perform this request on (ex,
> users/1/post/new), but this requires me to generate this path
> dynamically in the Rails script.

Maybe I'm missing something but ... You say 'everything' is working
fine without Ajax which, to me, means that you already know the user
id and are sending it to the view when you render the 'new' view.  The
user object is available to you in that view.  So there are a couple
of 'easy' approaches to your problem.  If you're doing a full page
render then you can do an erb substitution into the Ajax url in your
jQuery.  If you'd prefer to grab the user id via jQuery for whatever
reason, you can put it in the page via a hidden_field_tag when you
render the form and use that to construct your Ajax url, perhaps by
binding a function to the .submit.

HTH,
Bill

-- 
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to