Topic: Error occured while linking files in rails application

Hi,
I'm a beginner in rails, i have used code: <input type="button" value="Login" onClick="window.location='http://localhost:3000/logins/show.html'"/> but i got an active record error saying Couldn't find Login with id=show. I want the control to be shifted to new file called show.html when Login button is clicked. Can anybody be pls help me out...

Error message is as shown below

ActiveRecord::RecordNotFound in LoginsController#show

Couldn't find Login with id=edit

Rails.root: c:/Sites/onlogin1
Application Trace | Framework Trace | Full Trace

app/controllers/logins_controller.rb:16:in `show'

Request

Parameters:

{"id"=>"edit",
"format"=>"html"}

Show session dump

Show env dump
Response

Headers:

None

Re: Error occured while linking files in rails application

This needs a long explanation on how routes, ontrollers, links and buttons work in Rails.

i have used code: <input type="button" value="Login" onClick="window.location='http://localhost:3000/logins/show.html'"/>

In your views use the rails view helpers link_to and button_to.
The code you have there would have to be changed to point to a different location every time you changed the location of your app which is just a right royal pain in the posterior. Rails sets up routes for you to use in the routes.rb. Most are automatically generated for you when you create a new scaffold so you should make use of them
The equivalen to what you have there would be

<%=button_to('Login', login_path("edit"))%> 

But that wouldn't work for exactly the same reasons as your code wouldn't work.
That code doesn't care about the absolute path of your application as it is relevant to the root of your application only. There are other huge benefits to using the rails view helpers such as being able to automatically switch between http and https with a simple force ssl command and it allows you to make use of the asset_host so you can add an image_tag that shows an image located on a sperate server thereby speeding up site responsiveness dramatically, These are just a few of the benefits of using the Rails helpers. There are many more. In a nutshell use the Rails conventions, don't fight it.

The code you have there is calling the logins controller with an HTTP POST request. The show action of controllers is typically routed as an HTTP GET request, the route for the show action will be expecting the first parameter to be the id of the record you wish to show hence the id=>'edit'. in your params.

Use a link_to to get to HTTP GET requests. a login action rightly needs a button therefore the button needs to point to a POST or PUT request which will be routed to a create or update action in your controller. Thee actions would then redirect to the show or index actions.

The actual error you are seeing is because the show action will try to find a record in the database with an id taken from the parameters passed in

SmeModel.find(params[:id]) 

and there will be no record in whatever table the find is being done that has a value of "edit" in the id column.

This is a massive subject to cover, can I suggest you watch a few railscasts videos starting with http://railscasts.com/episodes/250-auth … om-scratch

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Error occured while linking files in rails application

BTW, I have deleted your duplicate posts. Please only post your question once.

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Error occured while linking files in rails application

Thank you jamesw for your reply.
Can I know how to make things such as textbox, buttons etc. dynamic in rails application

Re: Error occured while linking files in rails application

Not sure what you mean by dynamic?
You can check out the rails docs for a list of the view helpers and how they work
http://guides.rubyonrails.org/form_helpers.html

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)