Ruby on Rails
Thursday, May 3, 2012
Make sure this route comes before the route entry for the country resource.
On Thu, May 3, 2012 at 5:12 PM, akshar jamgaonkar <akshar.jamgaonkar@gmail.com> wrote:
Yes i have added....it looks like thismatch "/states/countries_state/:country_id" => "states#countries_state"On Thu, May 3, 2012 at 5:10 PM, Aziz Bookwala <aziz.bookwala@gmail.com> wrote:
Did you add a route for this new action?On Thu, May 3, 2012 at 5:08 PM, akshar jamgaonkar <akshar.jamgaonkar@gmail.com> wrote:
Thanks Aziz....... I have wriiten a countries_state action and in states controller, and in application.js i have modified the path like thisvar country_states_path = '/states/countries_state/'; however on console its giving me eroor like<pre>Couldn't find State with id=countries_state</pre> ... Iam struggling to find what;s going wrong as iam pretty new to all this...thanks a lot all of you for your help......
On Thu, May 3, 2012 at 5:03 PM, Aziz Bookwala <aziz.bookwala@gmail.com> wrote:Hey AJ
Yes, to serve any request made by your client, you would need something on the server to handle the request.
As for rendering the dropdown, this is a pretty simple thing to do with jQuery. Look around, you should find something quite easily.
On Thu, May 3, 2012 at 5:01 PM, akshar jamgaonkar <akshar.jamgaonkar@gmail.com> wrote:Hey Aziz,really thanks for you repl..........so do i need to write a controller action that would return me the states depending on the country and how do i render the state drop down in Cilent Form...Thanks....Thanks,AJOn Thu, May 3, 2012 at 4:46 PM, Aziz Bookwala <aziz.bookwala@gmail.com> wrote:
Hey AJ
In your ajax call, you need to pass the id of the selected state if you are using a nested resource url structure.
Your js would looks something like this:
$(document).ready(function() {
var country_states_path = '/countries/:id/states;
$("#client_country_id").change(function() {
var state_id = $(this).val();
$.ajax({
type: "GET",
url: country_states_path.replace(":id", id),
success: function(data) {
// Code to populate cities
}
});
});
});
Incase you are not using nested resources, you still need to pass the state_id that was selected currently. Using the below js, in your controller, the state id would be available as params[:state]
$(document).ready(function() {
var country_states_path = '/states/';
$("#client_country_id").change(function() {
var country_id = $(this).val();
$.ajax({
type: "GET",
data: {country: country_id},
url: country_states_path,
success: function(data) {
// Code to populate cities
}
});
});
});--
On Thu, May 3, 2012 at 12:42 PM, AJ <akshar.jamgaonkar@gmail.com> wrote:Hi Hassan,
I am Bit of a novoice to this...... iam nt sure wether this is correct
approach...in my application.js file i have wriiten
$(document).ready(function() {
$("#client_country_id").change(function() {
$.ajax({
type: "GET",
url: '/states/1',
success: function(data) {
// Code
}
});
});
});
and my clients form has state feidl like this
<div class="field row odd">
<%= f.label :state1 %>
<%= f.select 'state_id', State.find(:all).collect{|s|
[s.name,s.id]} %>
</div>
now i want to pass the country id and ftecth state depending on
it..... do i include the above div in a prtial and what to write in
the state controller.....
Thanks in advance.
Thanks & Regards,
On May 2, 7:14 pm, Hassan Schroeder <hassan.schroe...@gmail.com>
wrote:
> On Wed, May 2, 2012 at 7:06 AM, akshar jamgaonkar
>
> <akshar.jamgaon...@gmail.com> wrote:> Hassan Schroeder ------------------------ hassan.schroe...@gmail.comhttp://about.me/hassanschroeder
> > i have gone through this but it has an example where Javascript has been
> > used , i want to use AJAX and JQuery,
>
> So what's the problem? What have you tried so far, and how did it
> not work?
>
> --
> twitter: @hassan
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
- Aziz M. Bookwala
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--Thanks & Regards,
Akshar Jamgaonkar
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
- Aziz M. Bookwala
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
Thanks & Regards,
Akshar Jamgaonkar
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
- Aziz M. Bookwala
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
Thanks & Regards,
Akshar Jamgaonkar
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
- Aziz M. Bookwala
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment