Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to generate a method in my controller "Applications" in Ruby on Rails, bur i used scaffold and now I dont know if have to create a new view too.

  def list
    @applications = Application.all

  end

I only want that my controller give me all the applications objects, but I dont know if I have to create a new View.

share|improve this question
    
whats wrong with using the existing index action for this? –  sevenseacat Jul 30 '13 at 4:49

1 Answer 1

up vote 2 down vote accepted

Yes, you need a view if you are going to display the @applications. Create a new file app/views/applications/list.html.erb if you are using erb of course.

You also need to add a route to this list action if you haven't done that already. I'm assuming a get request as your code only shows retrieval of Application. In your config/routes.rb add the following lines:

resources :applications do 
  collection do 
    get :list
  end
end

Once these are done you'll have /applications/list path which will execute the list action of your ApplicationsController and the view list.html.erb.

share|improve this answer
    
Great answer. Very helpful =) But now, I want to know if i did the scaffolding, I have this in my routes "resources :applications", and when i use that code you told me I got that error: "undefined method `collections'". Am i doing something wrong? –  Cris Towi Jul 30 '13 at 4:44
    
@CrisTowi, sorry that was a typo. It should have been collection, not collections. Corrected my answer as well. –  vee Jul 30 '13 at 4:45
    
Great! Works perfectly. Very thank you. =) –  Cris Towi Jul 30 '13 at 4:48
    
@CrisTowi, Great. Glad to be of help. –  vee Jul 30 '13 at 4:57
    
@CrisTowi: Make sure you mark the answer. –  Daiku Jul 30 '13 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.