Routes and Forms

Hello G.s,

I am totally new to rails so sorry if I ask some silly questions, I am
also totally confused which is likely self inflicted!

So I am learning rails and rjs - I have two models

Manufacturers
Models

So Manufacturers would contain things like Ford, Aston Martin
and Models would contain the cars like

Ford -> Focus, Escort
Ferrari => DB7, DB6, DB5

So I have the simple rails framework working, so firstly a index of
‘Manufacturers’ would show all the Manufacturer’s, you could then click
a Manufacturer and it would display all the models for that
Manufacturer, and then you can click a Model and you can ‘edit’ that
models.

But what I want is to have them all on one page - so what I want is the
index page has a select, once you select a manufacturer it grabs all the
models and now displays them in a ‘select’ - you then chose a model and
it then loads the ‘edit’ page.

Now what I have done so far is in my index.erb

Listing Manufacturer

<% form_remote_for "manufacturer", :html => {:id => 'form1', :name => 'form1'} do |f| %>
Please select Manufacturer <%= collection_select(:manufacturer, :id, @manufacturer, :id, :manufacturer, {:include_blank => ''}, {:onchange => "document.form1.onsubmit()"}) %>
<% end %>

And my show.rjs

will do something like

page.replace_html :show_models, :partial => ‘show’, :object =>
@manufacturer

Now I tried to do something similar to the index.erb for each ‘model’
e.g.

Please select Model <%= collection_select(:model, :id, @manufacturers.models, :id, :title, {:include_blank => ''}, {:onchange => "document.form1.onsubmit()"}) %>

But of course this submits the form to the same controller/action for
the manufacturers not the models controller… Anyone got any advice on
how to do this sort of thing?

Much Appreciated

Paul

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs