Newbie - how to pass info from one screen to another

I know this is undoubtably a stupid question, but I beg your patience.
I’m just getting started and I used to program mostly in VB.

I have a company model/table and a quote model/table. When someone
clicks Create New Quote while viewing a Company, I’d like to bring them
to a new quote screen and then “set” the company name field on the new
quote screen to the name from the company screen that they just left.

Can someone explain how to do that?

Thank you!

there are several ways to do this :slight_smile:
assuming, that the routes are set

in your company view you simply add the company_id to the link

<%= link_to “Quote”, new_quote_path(:company_id => @company.id) %>

in you quotes_controller:

def new
@company = Company.find[params[:company_id])

end

and go in to you quote-view like:

<%= @company.name %>

Thanks, Thorsten.

When you say “assuming, that the routes are set” are you referring to
“belong_to” type statements or do I need to do something with the
config/routes file?

And, in this link “<%= link_to “Quote”, new_quote_path(:company_id =>
@company.id) %>” what is “new_quote_path”?

When you say “assuming, that the routes are set” are you referring to
“belong_to” type statements or do I need to do something with the
config/routes file?

yes, you must setup the routing, so that rails can find the right
controller and action. something like:

map.resources :companies
map.resources :quotes

And, in this link “<%= link_to “Quote”, new_quote_path(:company_id =>
@company.id) %>” what is “new_quote_path”?

new_quote_path generates a path/url for you, in this case to the new
action in the quotes controller (and with the additional parameter
company_id)

that’s for so called RESTful routing

Thank you very much for clarifying. Will read up on the routing chapter
ASAP. :slight_smile:

Denise R. wrote:

Thank you very much for clarifying. Will read up on the routing chapter
ASAP. :slight_smile:

yep, do so. there are so many ways. have a look at nested routes. this
would look like

map.resources :companies do |company|
company.resources :quotes
end

then you could use:

new_company_quote_path(@company.id)

with the same result (id in params[:company_id] ) as above

for RESTful routes have a look at this:

http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/

Welcome to Rails :slight_smile: It can take a while to make the switch from
Microsoft to Rails.

I’m finding that. /rueful grin/

Feel free to also use our forums that are setup especially for
Microsoft developers making the switch: forum.softiesonrails.com.

I will definitely check that out.

I’d also highly recommend a book like “Agile Web D. with
Rails” (from pragprog.com, you could just get the pdf if you want) or
“Ruby for Rails” by David A. Black. Both are really good for getting
off the ground with Rails.

I started with Ruby on Rails by Patrick Lenz (which I read cover to
cover) and then added Agile Web… (which I haven’t had time to read
except to look up problems).

I can get things happening if they’re in the same model, but I’m really
stumbling when it comes to referencing things outside the model I’m
currently working in. Perhaps the routing that Thorsten pointed out
will help with that. I’m also struggling with simple things like
building strings, so I added Ruby on Rails for Dummmies to my collection
because it was so easy to find do’s and don’t for simple syntax.

The other thing that’s really tripping me up is drop-down lists. Should
be super easy, but I still don’t have a working one. Every book and
code snippet has a little bit different syntax and none of them seem to
work. Again, I’m trying to reference data in another model, so maybe it
all comes back to that one issue. /shrug/

Just a bit frustrated right now… /sigh/

On Nov 13, 2:07 pm, Denise R. [email protected]
wrote:

I know this is undoubtably a stupid question, but I beg your patience.
I’m just getting started and I used to program mostly in VB.

Welcome to Rails :slight_smile: It can take a while to make the switch from
Microsoft to Rails.

Feel free to also use our forums that are setup especially for
Microsoft developers making the switch: forum.softiesonrails.com.

I’d also highly recommend a book like “Agile Web D. with
Rails” (from pragprog.com, you could just get the pdf if you want) or
“Ruby for Rails” by David A. Black. Both are really good for getting
off the ground with Rails.

Our blog also tends to focus on Microsoft-to-Rails topics from time to
time.

Hope this helps.

Jeff

essentialrails.com