0

I'm new to rails, and am trying to create a simple credit card managing application. I want to have a basic authentication, where the user is presented with a simple form:

  • 4 input fields, each for 4 numbers of the credit card
  • 1 input field for the pin number.

This search form should be in a separate page (as per the application specifications), and then it should redirect to the page with the details of the card (if found).

I'm still getting the hang of controllers and their actions, and am not sure about creating a new action in the cards_controller and its respective view, only to display the form and then manage the search in the show action. I don't want to got through creating a whole search controller as some authors suggest, and instead keep it simple. What would be a good restful approach to this situation?

Daniel Estrada
  • 926
  • 8
  • 9

1 Answers1

2

Here's a good answer about RESTful routes and search: https://stackoverflow.com/a/1081720/648392

Regarding the search form, you could do it like this:

  • Create a search action in the cards_controller
  • Add a route for the search action to routes.rb.

The route could look something like this:

resources :cards do 
  # This will create a route that looks like this: /cards/search
  collection do 
    get "search"
  end
end
  • Create the needed form in some existing view, or create a new action, in cards_controller and corresponding view for it. Use the form to send the search parameters in a GET request.
  • Use whatever params you need in the search action to populate an list of cards.
  • Render the results in the search view
Community
  • 1
  • 1
Jesper
  • 4,535
  • 2
  • 22
  • 34