Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why getting undefined method? #54

Closed
angelacode opened this issue Jun 13, 2011 · 13 comments
Closed

why getting undefined method? #54

angelacode opened this issue Jun 13, 2011 · 13 comments

Comments

@angelacode
Copy link

I am getting the following error:

undefined method `account_name' for #Message:0xb5bddb88

I followed the README for my case and have the following:

  = f.autocompleted_input :account_name, :url => autocomplete_account_name_messages_path

And in the messages controller for which this form is using:

1 class MessagesController < ApplicationController
2 before_filter :authenticate_user!
3 autocomplete :account, :name, :full => true

@dabit
Copy link
Contributor

dabit commented Jun 13, 2011

Does your Message model has an attribute account_name ?

If it doesn't or you don't need it perhaps you can add it using attr_accessor :account_name

@angelacode
Copy link
Author

the messsage model doesn't have attr_accessor...should I add it? I didn't see it in the README...trying it now!

@angelacode
Copy link
Author

hmmm....still not workin...?

@angelacode
Copy link
Author

I added attr_accessor :account_name -- in my other app where I used this, I didn't have to do that....what else could be doing this? where is the "account_name" method created (equivalent to brand_name)

@zallesov
Copy link

same for me. attr_accessor is a workaround. i't should not be complicated.

@ilankasan
Copy link

Did you ever get this resolved? I am facing a similar isseu

@dabit
Copy link
Contributor

dabit commented Oct 4, 2011

This gem does nothing to create the attribute on the model that will receive the autocompleted input. :account_name must be either a database field on the model or a attribute added via attr_accessor

@dabit dabit closed this as completed Oct 4, 2011
@vandamon
Copy link

vandamon commented Nov 2, 2012

The example provided is incorrect? In the example, the model (Brand) is different from the controller (Product) and still in the View, we have:

form_for @product do |f| f.autocomplete_field :brand_name, autocomplete_brand_name_products_path end

Clearly name is a database field of Brand and not Product. And this is exactly what my requirement is, but it is not working with the same issue/error message.

@sidk
Copy link

sidk commented May 3, 2014

I was having the same issue as above, following along with the readme. The change which made it work was use :name instead of :brand_name (basically exactly what you would use with any other form helper). Maybe the readme needs to be updated?

@AmerPandzo
Copy link

Sidk , How is it that is doesn't use :name of upper model ... you use :name already in Master model :/

@sidk
Copy link

sidk commented Dec 7, 2014

Not sure I understand the question, because you can of course have the same
attribute name in different models.

On Thursday, November 27, 2014, AmerPandzo notifications@github.com wrote:

Sidk , How is it that is doesn't use :name of upper model ... you use
:name already in Master model :/


Reply to this email directly or view it on GitHub
#54 (comment)
.

@AmerPandzo
Copy link

I see that you didn't understood. You have form_for @Product do |f| ... PRODUCT .. DO F ... not account or some other model .. .so if i have :name in products , and :name in accounts .. your alleged usage of :name INSIDE OF form_for @Product do |f| ... f.name ... could not give you name of account , it will give you a product name .. not account that we are suppose to get ...

@sidk
Copy link

sidk commented Dec 8, 2014

Oh, I see where the confusion is. You're right that f.name is for @Product. The form is for creating a product and as such the form helper should use either a column in the Product table or an attr_accessor set on the Product model.

autocomplete_brand_name_products_path and the rest of the setup done for the Brand model and the welcome controller (in the readme) is where it'll get the brand names from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants