简体   繁体   中英

wrong number of arguments (1 for 0) Ruby on Rails

Hi I have posted the code first and the question below

 def create

     new_tag = Tag.new(name: params[:create_new][:name],
                       description: "TEST STRING", #TODO
                       user: @current_user,)

     if new_tag.save
        create_assignment_tag_association_from_tag_id(params[:assignment_id], new_tag.id)
        flash[:success] = I18n.t('tag created successfully')
        redirect_to :back
     else
        flash[:error] = I18n.t('error creating tag')
        redirect_to :back
     end
  end

  def create_assignment_tag_association_from_tag_id(assignment_id, tag_id)
    puts "assignment_id: #{assignment_id}"
    puts "tag_id: #{tag_id}"

    tag = Tag.find(tag_id)
    create_assignment_tag_association_from_tag(assignment_id, tag)
  end

  def create_assignment_tag_association_from_tag(assignment_id, t)
    if !t.assignment.exists(assignment_id)
      assign = Assignment.find(assignment_id)
      t.assignments << (assign)
    end
  end

wrong number of arguments (1 for 0) Rails.root: /Markus

Application Trace | Framework Trace | Full Trace

app/controllers/tags_controller.rb:84:in `create_assignment_tag_association_from_tag'
app/controllers/tags_controller.rb:80:in `create_assignment_tag_association_from_tag_id'
app/controllers/tags_controller.rb:18:in `create'

I'm confused as to why Ruby thinks create_assignment_tag_association_from_tag takes 0 arguments and why it thinks its only getting 1?

Note: I'm only calling create_assignment_tag_association_from_tag_id currently to show that that method takes two arguments and RonR recognizes that it takes two and is getting passed two. Because that call works, I'm confused as to why the second fn call is not working.

The issue isn't create_assignment_tag_association_from_tag , the issue is inside that function. exists is wrong. You're after exists? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM