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

undefined local variable or method `account' #22

Open
dbbooke opened this issue Aug 28, 2018 · 5 comments
Open

undefined local variable or method `account' #22

dbbooke opened this issue Aug 28, 2018 · 5 comments

Comments

@dbbooke
Copy link

dbbooke commented Aug 28, 2018

Hi, might be a dumb question but for some reason when I put this code in my views I get this error. undefined local variable or method `account'

I should be defining account as a variable in my controller right?

<%= link_to 'invite a friend',
new_invite_path(invite: { invitable_id: account.id, invitable_type: 'Account' } ) %>``

@tomichj
Copy link
Owner

tomichj commented Aug 28, 2018

Not a dumb question at all, I definitely need to expand and clean up the documentation. The "account" is a resource you're inviting people to join for this particular example. You would plug in whatever resource your users are sending invites to join. In this example, I was using the Basecamp-style concept of account.

@dbbooke
Copy link
Author

dbbooke commented Aug 28, 2018

Awesome. It seem like that error went away but for reason another one popped up?
screen shot 2018-08-28 at 12 01 08 pm

@tomichj
Copy link
Owner

tomichj commented Aug 28, 2018

You're getting 'undefined method: invitable_name'. The method invitable_name is added by the invitable mixin. The readme has a section about it. Basically, any resource you want to invite users to, should call invitable and tell it how to "name" the resource.

class Company < ActiveRecord::Base
  invitable named_by: :name
end

Here, Company has an attribute 'name' that is used as the 'invitable_name'. Anytime an invitation is generated to a Company resource, the invitable_name (which fetches name) will be used in the invitation.

@dbbooke
Copy link
Author

dbbooke commented Aug 29, 2018

Thanks! I have no errors now. Just one more question, if i wanted to over ride the config/locales/invitation.en.yml default messages how can I? I saw something about i18n translations. I just never worked with it before.

Also, I have no errors but the email doesn't actually send through. I changed the initializer/invitation.rb sender email. Do I have to use a third party app like sendgrid for the actual message to deliver? I see in the invites_controller.rb file theres a method 'def deliver_email' and it uses the deliver_later gem. However, that gem is outdated and not maintained anymore.

@tomichj
Copy link
Owner

tomichj commented Aug 29, 2018

The default translations live in the gem at config/locales/invitation.en.yml. You can make your own locale file in your app (in config/locales) and just overload any values you want to modify. There's also a generator included with invitation that will install a copy of the locale files in your app, along with the mailer views, so that you can completely change the emails if you want. To run that generator: rails generate invitation:views.

Regarding sending email: you're correct, you'll need to configure your rails app to send email through... something. It could be your local host, but I would recommend using a service like Sendgrid. I use Sendgrid on heroku, it's easy to use and it's free for low-volume apps.

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

2 participants