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
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.
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?
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.
In 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.
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"}
--