0
def delete_homework
   Homework.all(:conditions => {:teacher => params.require(:teacher) })

   redirect_to :back
end

This is my controller

<div class="row">
  <div class="col s12">
    <div class="card blue-grey lighten-2">
      <div class="card-content white-text">
        <span class="card-title">Delete Homework</span>
        <form action="/welcome/delete_homework">
          <input type="text" name="teacher" placeholder="Teacher Name">
          <input class="btn waves-effect waves-light" type="submit">
        </form>
      </div>
    </div>
  </div>
</div>

This is the HTML side.

When I try this, ruby gives ArgumentError in WelcomeController#delete_homework wrong number of arguments (given 1, expected 0)

what's wrong? please help. Thank you in advance

3
  • How you define route for delete_homework action? Commented Mar 24, 2017 at 4:22
  • The all(:conditions =>...) syntax was used in Rails up to version 2.3 and doesn't work anymore in newer versions. Whatever book oder tutorial you found with a code example with that syntax - it is outdated for at least 5 years... Commented Mar 24, 2017 at 7:34
  • @ashvin Rails.application.routes.draw do get 'welcome/index_array' get 'welcome/index_hash' get 'welcome/index_db' get 'welcome/create_homework' get 'welcome/delete_homework' get 'welcome/index_manage' Commented Mar 26, 2017 at 2:24

2 Answers 2

2

Change this line:

Homework.all( your_conditions )

to:

Homework.where( your_conditions )

The all method can't take any parameters. It should only be used when you simply want to grab all the records of a given model from the database.

Sign up to request clarification or add additional context in comments.

Comments

2

Try this

Homework.where(:teacher => params[:teacher])

2 Comments

Thanks for helping a noob... one more question. What is the code to delete a db with the param teacher?
homeworks = Homework.where(:teacher => params[:teacher]) homeworks.delete_all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.