Hello I have the following situation This is my controller: def addcar @car = Car.new(params[:car]) render :action => "list" endthis is my view: <%(@allcars).each do |cell|%> <%= link_to cell.to_s, :controller => "car", :action => "addcar", :car => cell.to_s %> <%end %> In the link_to statement I want to pass cell.to_s to the controller. how can i do that please? THe cell.to_s is just a string but I want it to be the name of the car object (car.Name) In other words I want to pass "Honda" to the controller so that I can save this to the cars table Id Name (Autogenerated) Honda (Autogenerated) Mercedes etc -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What is not working? On Nov 29, 3:40 pm, Char <charlene...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello > > I have the following situation > This is my controller: > > def addcar @car = Car.new(params[:car]) render :action > => "list" endthis is my view: <%(@allcars).each do |cell|%> > > <%= link_to cell.to_s, :controller => "car", :action => "addcar", :car > => cell.to_s %> > > <%end %> > > In the link_to statement I want to pass cell.to_s to the controller. > how can i do that please? THe cell.to_s is just a string but I want it > to be the name of the car object (car.Name) > > In other words I want to pass "Honda" to the controller so that I can > save this to the cars table > Id Name > (Autogenerated) Honda > (Autogenerated) Mercedes > > etc-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Nov-30 08:46 UTC
Re: pass parameters through link_to in a list
cell.name ? cell is the object, so .to_s method is going to print out the object summary On Nov 29, 10:26 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is not working? > > On Nov 29, 3:40 pm, Char <charlene...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello > > > I have the following situation > > This is my controller: > > > def addcar @car = Car.new(params[:car]) render :action > > => "list" endthis is my view: <%(@allcars).each do |cell|%> > > > <%= link_to cell.to_s, :controller => "car", :action => "addcar", :car > > => cell.to_s %> > > > <%end %> > > > In the link_to statement I want to pass cell.to_s to the controller. > > how can i do that please? THe cell.to_s is just a string but I want it > > to be the name of the car object (car.Name) > > > In other words I want to pass "Honda" to the controller so that I can > > save this to the cars table > > Id Name > > (Autogenerated) Honda > > (Autogenerated) Mercedes > > > etc-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
I didn''t add the routing properly :S Now that i''m in my car controller, I want to call a view in the user views. How do i go from the controller to the view??? Thanks 2009/11/30 lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> cell.name ? cell is the object, so .to_s method is going to print out > the object summary > > On Nov 29, 10:26 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > What is not working? > > > > On Nov 29, 3:40 pm, Char <charlene...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hello > > > > > I have the following situation > > > This is my controller: > > > > > def addcar @car = Car.new(params[:car]) render :action > > > => "list" endthis is my view: <%(@allcars).each do |cell|%> > > > > > <%= link_to cell.to_s, :controller => "car", :action => "addcar", :car > > > => cell.to_s %> > > > > > <%end %> > > > > > In the link_to statement I want to pass cell.to_s to the controller. > > > how can i do that please? THe cell.to_s is just a string but I want it > > > to be the name of the car object (car.Name) > > > > > In other words I want to pass "Honda" to the controller so that I can > > > save this to the cars table > > > Id Name > > > (Autogenerated) Honda > > > (Autogenerated) Mercedes > > > > > etc > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
use @car = Car.create( :name => params[:car]) , or @car = Car.find_or_create_by_name(params[:car]) if you don''t want duplicate items. On Tue, Dec 1, 2009 at 3:34 AM, charlene cassar <charlenecas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I didn''t add the routing properly :S > > > Now that i''m in my car controller, I want to call a view in the user views. > How do i go from the controller to the view??? > > > Thanks > > 2009/11/30 lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <lancecarlson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > cell.name ? cell is the object, so .to_s method is going to print out >> the object summary >> >> On Nov 29, 10:26 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > What is not working? >> > >> > On Nov 29, 3:40 pm, Char <charlene...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> > >> > > Hello >> > >> > > I have the following situation >> > > This is my controller: >> > >> > > def addcar @car = Car.new(params[:car]) render :action >> > > => "list" endthis is my view: <%(@allcars).each do |cell|%> >> > >> > > <%= link_to cell.to_s, :controller => "car", :action => "addcar", :car >> > > => cell.to_s %> >> > >> > > <%end %> >> > >> > > In the link_to statement I want to pass cell.to_s to the controller. >> > > how can i do that please? THe cell.to_s is just a string but I want it >> > > to be the name of the car object (car.Name) >> > >> > > In other words I want to pass "Honda" to the controller so that I can >> > > save this to the cars table >> > > Id Name >> > > (Autogenerated) Honda >> > > (Autogenerated) Mercedes >> > >> > > etc >> >> -- >> >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Liu Lantao College of Information Science and Technology, Beijing Normal University EMAIL: liulantao ( at ) gmail ( dot ) com ; WEBSITE: http://www.liulantao.com/ . ------ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.