Couple newbie questions

Hello Folks,

I am starting out with RoR and just browsed through Dave’s book â??
couldn’t
stop reading. I started building a prototype to get better hands on
experience and I have run into two simple issues that I am hoping will
be a
quick answer for some of you experts out there.

Issue 1:

From within a “companies” controller and list_companies.rhtml view there I
am trying to redirect to another controller and another action to enable
adding of comment. Something like the following â??

    <%= link_to "Comment", { # link_to options

                            *:contoller* => 'comment',

                            *:action* => 'add_comment',

                            *:id* => company},

                            { # html options

                                *:post* => *true*

                            }

When I click on the “Comment” link generated by the code above it tries
to
go to this url
http://localhost:3000/company/add_comment/9?contoller=commentbut
gives an error saying “No action responded to add_comment” obviously
because I don’t have an add_comment action under company controller but
have
that under comment controller where I am trying to redirect to. How do I
make it go to the add_comment view under comment controller? Do I need
to
modify the routing requests or am I doing something incorrect with the
way I
am try to redirect?

*Issue 2: ***

I have a user view where I am trying to take in user login and address
data.
I have two models, user and address, where user has_one address and
address
belongs_to user. With just user specific data the form works fine
(truncated
version below) but when I try to add address specific input data I am
not
quite sure how to set that up in the form and how to pass that data into
the
address model/table. There must be a standard way for doing something
like
this and I might have missed it in Dave’s book. Any pointers/answers you
folks can provide would be helpful. I tried adding the :address after
:user
and text_fields like address_name but get errors when rails tries to
render
the page.

<% form_for :user do |form| %>

  <p>

    <label for="user_name">Name:</label>

    <%= form.text_field *:username*, *:size* => *40* %>

  </p>

<% end %>

Thanks for any help you folks can provide.

Sanjay.

For issue #1 try:

<%= link_to “Comment” , :controller => ‘comment’ ,

                                  *:action* => 'add_comment' ,

                                  *:id* => company %>

You mispelled controller :wink: Also, you don’t need the post action in
there.

On Jun 28, 2006, at 12:25 AM, Sanjay T. wrote:

there I am trying to redirect to another controller and another
When I click on the “Comment” link generated by the code above it
tries to go to this url http://localhost:3000/company/add_comment/9?
contoller=comment but gives an error saying “No action responded to
add_comment” obviously because I don’t have an add_comment action
under company controller but have that under comment controller
where I am trying to redirect to. How do I make it go to the
add_comment view under comment controller? Do I need to modify the
routing requests or am I doing something incorrect with the way I
am try to redirect?

spell “contRoller” and it might work better
:controller => ‘comment’,

pointers/answers you folks can provide would be helpful. I tried
Thanks for any help you folks can provide.

Sanjay.

Check out Amy Hoy’s presentation from RailsConf (http://
www.slash7.com/presentations/overcoming_scaffolding_addiction.pdf)
particularly around slide 57… (though you’ll have to look at many
of the ones leading up to there if you want to see where she’s going).

-Rob

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