dougiebuckets
dougiebuckets

Reputation: 2453

'wrong number of arguments (0 for 1)' error when using link_to to pass variable from view to controller

I'm trying to use link_to to pass a variable from a view to a controller. Here's what my code in the view looks like:

<%= link_to 'Send Chant', :controller => 'send_chants', :action => 'index', :content => @chant.content %></b>

Here's what the index action in my 'send_chants' controller looks like:

class SendChantsController < ApplicationController
  def index(content)

    puts content

  end
end

Upon clicking the 'Send Chant' link, I get a ArgumentError 'wrong number of arguments (0 for 1)'

I'm sure I'm missing something simple. Any thoughts?

Thanks so much!

Upvotes: 0

Views: 4274

Answers (1)

Doon
Doon

Reputation: 20232

Controller actions do not take parameters. All params are passed in via the params hash.. Try something like...

class SendChantsController < ApplicationController
  def index
    puts params[:content]
  end
end

Upvotes: 5

Related Questions