I start apologies for the silly question..but: how do I show the content of a view in a controller by url I mean why, with the starting rails conf and I simple scaffold done, i can''t do root/:controller/:action and see the action.html.erb content? it warns me writing "Couldn''t find Product with ID=new2" where new2 is an empty method in the controller and with a new2.html.erb file existing in the view/controller_name folder I had my guess..but I''d like to better understand how to do this.. I mean..is this about the routes.rb configuration? or there''s a way to fill the method, don''t know some particular use of respond_to ?! I know it''s a really stupid question..but still can''t figure out how this work. thanks since now :) andrea -- 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.
Andrea, You need to provide us with more information. From the info you have given I cannot figure out what is going on.> "Couldn''t find Product with ID=new2"You say that you have an empty method, but it is trying to find a Product with ID=new2. I think that it cannot find the correct route from the routes.rb file. Actually you should paste all the code snippets from your controller, view and routes.rb file. Punit -- Posted via http://www.ruby-forum.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.
Ok..so that''s what I mean: I need to create a new view where I want to insert for istance (and in this exact case) a form that I use to upload a file and then process the file. So in first place I create a view "new2.html.erb" in my view folder associated to a controller let''s say "references" with a form in it. so now i have in the "view/references" folder this new file how can I access this view? can I without creating a method? I guess I don''t because when I type http://localhost:3000/references/new2 i get that error: "Couldn''t find Reference with ID=new2" (but it render the page with the form if I had any kind of id after, i.e. http://localhost:3000/references/new2/1 ) the question is: why for istance the "index" page or the "new" generated by the scaffold can render the page (and the form in case of new) without passing any ID and I can''t now? what''s the rule underneath? my new2.html.erb page contain this: -- <h1>New reference csv</h1> <% form_for :reference, @references, :method => :get, :url => {:action => ''new''} do %> <p>Filename: <%= text_field_tag "file_tag" %> </p> <p> <%= submit_tag("Carica csv") %></p> <% end %> <%= link_to ''Back'', references_path %> -- (I''ve redefined the new method to parse a csv file) and the routes.rb is the default one given by rails with the only restful defined like this: -- map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' -- I''ve tried to add something like: map.connect '':controller/:action.:format'' but it does not do the trick .. :D I''d like to understand how this work in general more than solve this particular problem :) thank u all :) andrea On 11 Mar, 22:41, Punit Rathore <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Andrea, > > You need to provide us with more information. From the info you have > given I cannot figure out what is going on. > > > "Couldn''t find Product with ID=new2" > > You say that you have an empty method, but it is trying to find a > Product with ID=new2. I think that it cannot find the correct route from > the routes.rb file. > > Actually you should paste all the code snippets from your controller, > view and routes.rb file. > > Punit > > -- > Posted viahttp://www.ruby-forum.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.
Andrea,> how can I access this view? can I without creating a method? I guess I > don''t because when I type http://localhost:3000/references/new2 i get > that error: > "Couldn''t find Reference with ID=new2" > (but it render the page with the form if I had any kind of id after, > i.e. http://localhost:3000/references/new2/1 )You routes.rb file would also have this line. map.resources :references What this does is that it creates RESTful urls for references. You should read up on restful routes. Since the routes.rb files is read top-down, the RESTful url for references gets more priority over map.connect '':controller/:action/:id'' So maybe you should add a named route for your new2 method(and make sure its before the map.resources line in your routes.rb) or another controller to handle uploading of files. Punit>-- Posted via http://www.ruby-forum.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.
right! thx for reply.. I''m going to read a basic restful/routes guide I guess it''s something dealing with GET or POST method thx :) On 12 Mar, 09:02, Punit Rathore <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Andrea, > > > how can I access this view? can I without creating a method? I guess I > > don''t because when I typehttp://localhost:3000/references/new2i get > > that error: > > "Couldn''t find Reference with ID=new2" > > (but it render the page with the form if I had any kind of id after, > > i.e.http://localhost:3000/references/new2/1) > > You routes.rb file would also have this line. > map.resources :references > > What this does is that it creates RESTful urls for references. You > should read up on restful routes. > > Since the routes.rb files is read top-down, the RESTful url for > references gets more priority over map.connect > '':controller/:action/:id'' > > So maybe you should add a named route for your new2 method(and make sure > its before the map.resources line in your routes.rb) or another > controller to handle uploading of files. > > Punit > > > > -- > Posted viahttp://www.ruby-forum.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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I meant GET or POST request ;) On 12 Mar, 09:02, Punit Rathore <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Andrea, > > > how can I access this view? can I without creating a method? I guess I > > don''t because when I typehttp://localhost:3000/references/new2i get > > that error: > > "Couldn''t find Reference with ID=new2" > > (but it render the page with the form if I had any kind of id after, > > i.e.http://localhost:3000/references/new2/1) > > You routes.rb file would also have this line. > map.resources :references > > What this does is that it creates RESTful urls for references. You > should read up on restful routes. > > Since the routes.rb files is read top-down, the RESTful url for > references gets more priority over map.connect > '':controller/:action/:id'' > > So maybe you should add a named route for your new2 method(and make sure > its before the map.resources line in your routes.rb) or another > controller to handle uploading of files. > > Punit > > > > -- > Posted viahttp://www.ruby-forum.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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 March 2010 13:40, adedip <adedip-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> right! > thx for reply.. > I''m going to read a basic restful/routes guideIn case you have not seem there there are excellent guides at http://guides.rubyonrails.org/ including one on routing. I would suggest starting with Getting Started however which will explain the basic principles of rails, then work through the others. Colin -- 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.
just add map.resources :referenced , :collection => { ''new2'' => ''get'' } On Mar 12, 6:44 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 12 March 2010 13:40, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > right! > > thx for reply.. > > I''m going to read a basic restful/routes guide > > In case you have not seem there there are excellent guides athttp://guides.rubyonrails.org/including one on routing. I would > suggest starting with Getting Started however which will explain the > basic principles of rails, then work through the others. > > Colin-- 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.
Hi guys..I did try almost everything..but still cant'' get any result.. Starting from a simple "scaffold" creating a class called "reference" I have updated the controller with this 2 methods: -- def load end def upload require ''fastercsv'' filename = params[:file_tag] FasterCSV.foreach("public/trac/#{filename}", {:col_sep => ";"} ) do |row| Reference.create(:idarticolo => row[0], :nomefilefoto => row[1], :cancellato => row[2] ) end respond_to do |format| format.html # new.html.erb format.xml { render :xml => @reference } end end -- the I''ve added a view file in the "app/view/reference" folder called "load.html.erb" with this code: -- <h1>New reference</h1> <% form_for :reference, @references, :method => :get, :url => {:action => ''upload''} do %> <p>Filename: <%= text_field_tag "file_tag" %> </p> <p> <%= submit_tag("Load csv") %></p> <% end %> <%= link_to ''Back'', references_path %> -- then I''ve updated the routes.rb file with this line (do I have to replace the already in "map.resources :references" or do i add this second new line?): -- map.resources :references, :collection => {"load" => "get"} -- going to url: http://localhost:3000/references/load I get this error message: -- ActiveRecord::RecordNotFound in ReferencesController#show Couldn''t find Reference with ID=load RAILS_ROOT: /Users/adedip/Lavoro/antonioli1 Application Trace | Framework Trace | Full Trace /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ base.rb:1586:in `find_one'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ base.rb:1569:in `find_from_ids'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ base.rb:616:in `find'' /Users/adedip/Lavoro/antonioli1/app/controllers/ references_controller.rb:25:in `show'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:1331:in `send'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:1331:in `perform_action_without_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ filters.rb:617:in `call_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ filters.rb:610:in `perform_action_without_benchmark'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue'' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/ core_ext/benchmark.rb:17:in `ms'' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/ core_ext/benchmark.rb:17:in `ms'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ rescue.rb:160:in `perform_action_without_flash'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ flash.rb:146:in `perform_action'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:532:in `send'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:532:in `process_without_filters'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ filters.rb:606:in `process'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:391:in `process'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ base.rb:386:in `call'' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ routing/route_set.rb:437:in `call'' -- If I add any number at the end of the url it works perfectly (i.e. http://localhost:3000/references/load/1 ) what am I doing wrong? can someone explain me the process to get this work? thanks in advance :) Andrea On 13 Mar, 05:34, RavionRails <ravindrasing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> just add > map.resources :referenced , :collection => { ''new2'' => ''get'' } > > On Mar 12, 6:44 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > On 12 March 2010 13:40, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > right! > > > thx for reply.. > > > I''m going to read a basic restful/routes guide > > > In case you have not seem there there are excellent guides athttp://guides.rubyonrails.org/includingone on routing. I would > > suggest starting with Getting Started however which will explain the > > basic principles of rails, then work through the others. > > > Colin-- 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 guess is something dealing with this: attr_accessor :name isn''t it? On 15 Mar, 14:16, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi guys..I did try almost everything..but still cant'' get any result.. > > Starting from a simple "scaffold" creating a class called "reference" > I have updated the controller with this 2 methods: > -- > def load > > end > > def upload > require ''fastercsv'' > filename = params[:file_tag] > FasterCSV.foreach("public/trac/#{filename}", {:col_sep => ";"} ) > do |row| > Reference.create(:idarticolo => row[0], :nomefilefoto => row[1], > :cancellato => row[2] ) > end > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @reference } > end > end > -- > > the I''ve added a view file in the "app/view/reference" folder called > "load.html.erb" > with this code: > > -- > <h1>New reference</h1> > <% form_for :reference, @references, :method => :get, :url => > {:action => ''upload''} do %> > > <p>Filename: <%= text_field_tag "file_tag" %> </p> > > <p> <%= submit_tag("Load csv") %></p> > <% end %> > <%= link_to ''Back'', references_path %> > -- > > then I''ve updated the routes.rb file with this line (do I have to > replace the already in "map.resources :references" or do i add this > second new line?): > -- > map.resources :references, :collection => {"load" => "get"} > -- > > going to url:http://localhost:3000/references/loadI get this error > message: > -- > ActiveRecord::RecordNotFound in ReferencesController#show > > Couldn''t find Reference with ID=load > > RAILS_ROOT: /Users/adedip/Lavoro/antonioli1 > Application Trace | Framework Trace | Full Trace > > /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > base.rb:1586:in `find_one'' > /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > base.rb:1569:in `find_from_ids'' > /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > base.rb:616:in `find'' > /Users/adedip/Lavoro/antonioli1/app/controllers/ > references_controller.rb:25:in `show'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:1331:in `send'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:1331:in `perform_action_without_filters'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > filters.rb:617:in `call_filters'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > filters.rb:610:in `perform_action_without_benchmark'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > benchmarking.rb:68:in `perform_action_without_rescue'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/ > core_ext/benchmark.rb:17:in `ms'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/ > core_ext/benchmark.rb:17:in `ms'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > benchmarking.rb:68:in `perform_action_without_rescue'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > rescue.rb:160:in `perform_action_without_flash'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > flash.rb:146:in `perform_action'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:532:in `send'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:532:in `process_without_filters'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > filters.rb:606:in `process'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:391:in `process'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > base.rb:386:in `call'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ > routing/route_set.rb:437:in `call'' > -- > > If I add any number at the end of the url it works perfectly (i.e.http://localhost:3000/references/load/1) > > what am I doing wrong? > can someone explain me the process to get this work? thanks in > advance :) > > Andrea > > On 13 Mar, 05:34, RavionRails <ravindrasing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > just add > > map.resources :referenced , :collection => { ''new2'' => ''get'' } > > > On Mar 12, 6:44 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > On 12 March 2010 13:40,adedip<ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > right! > > > > thx for reply.. > > > > I''m going to read a basic restful/routes guide > > > > In case you have not seem there there are excellent guides athttp://guides.rubyonrails.org/includingoneon routing. I would > > > suggest starting with Getting Started however which will explain the > > > basic principles of rails, then work through the others. > > > > Colin-- 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.
>then I''ve updated the routes.rb file with this line (do I have to >replace the already in "map.resources :references" or do i add this >second new line?): >-- > map.resources :references, :collection => {"load" => "get"} >--You have to replace the line. -- Posted via http://www.ruby-forum.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.