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 Iam 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/8449d6c5/attachment-0001.html
For issue #1 try:
<%= link_to "Comment" , *:controller* =>
''comment'' ,
*:action* =>
''add_comment'' ,
*:id* => company %>
You mispelled controller ;) Also, you don''t need the post action in
there.
On 6/27/06, Sanjay Tibrewal <stibrewal@gmail.com>
wrote:>
> 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=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?
>
>
>
> *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.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
--
Ryan Prins
rprins@gmail.com
http://www.lazyi.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/0ce25a36/attachment.html
On Jun 28, 2006, at 12:25 AM, Sanjay Tibrewal wrote:> 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=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'',> 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.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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/65f14ab1/attachment-0001.html
Thank you folks for the quick response. And stupid of me for the typo in the first case. Sanjay. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/15ce55dc/attachment.html