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

Route issue. #53

Open
houmanka opened this issue Jan 21, 2014 · 14 comments
Open

Route issue. #53

houmanka opened this issue Jan 21, 2014 · 14 comments

Comments

@houmanka
Copy link

Hi guys,
I have just installed blogit into my Rails 4 application. When I go to /blog I get routing error of every single route I have got. I get "undefined local variable or method". It is like that it won't load my router at all.

Not sure if it make sense though. Please let me know what you want me to put here so you guys can have a look.

I have current_user defined in ApplicationController.
In the installation what I didn't understand is "declare which of your models acts as blogger in your app".
Where should I declare that? so that might be the issue here.

Thanks in advance.

@Bodacious
Copy link
Owner

Hi @houmanka - you have to call the blogs() method in your user model.

class User < ActiveRecord::Base

  blogs
end

Thats what we mean by "declare which of your models acts as blogger in your app"

@emaxon
Copy link

emaxon commented Jan 21, 2014

@houmanka

When you say router, are you referring to routes? If so, I think the following section in the Rails guide should help.

http://edgeguides.rubyonrails.org/engines.html#routes

Basically, when on a page within the Blogit engine, you need to specify main_app prior to your normal app's path. For example, main_app.root_path. Likewise, outside of the Blogit engine, your paths need to be blogit.blog_path.

However, line 82 of the blogit.rb initializer allows you "to call named routes without the main_app prefix." Here's the link to that file within the sample Blogit app.

https://github.com/KatanaCode/BlogitExample/blob/master/config/initializers/blogit.rb

@houmanka
Copy link
Author

Hi @emaxon
I haven't change anything in the blogit engine. I followed the installation and then I typed /blog in the url.

This is my route file:

ProjectName::Application.routes.draw do
  mount Blogit::Engine => "/blog"
  resources :finance_quotes
  root to: 'static_pages#home'
  resources :users
end

If I go to any other page all are fine and there is no rounting or method error.

Thanks again for your help.

screen shot 2014-01-22 at 2 04 29 pm

@emaxon
Copy link

emaxon commented Jan 22, 2014

Hi @houmanka,

The problem exists in your View — specifically your _header.html.erb

You need to either prepend all of your paths with main_app.path_name (ie. main_app.user_path) OR uncomment line 82 of the config/initializers/blogit.rb file (remember to restart your Rails server if you do this).

Basically, when you are go to your blog, you are within the Blogit engine and must specify that the paths are external to that engine.

@houmanka
Copy link
Author

I have added main_app as prefix to all of my links and everything works. Thank you.

Now I get a new error:
Authentication does work because when I logout I can't see the "New Blog post".
When I login and I click on the "New Blog post" I get this error:
undefined local variable or method `login_required' for #Blogit::PostsController:0x007fc331b1d9a0

Thanks again for your help mate.

@emaxon
Copy link

emaxon commented Jan 22, 2014

Can you post your application_controller.rb?

My only point of reference on this will be the file provided in the example Blogit repo here:

https://github.com/KatanaCode/BlogitExample/blob/master/app/controllers/application_controller.rb

@houmanka
Copy link
Author

hmmm,
Mine is different:

I have made my own Authentication and using Declarative Authorisation for the Access List.
Anyway I have added the login_required mothod and all are good.

Now when I try to save the post I get User#username is not defined
Do I need to make this in the User table? my authentication is based on the email and password.

Thanks again guys.

@Bodacious
Copy link
Owner

I think this might be because the show action will, by default, call the display name method. See the config template config.blogger_display_name_method = :your_method_name_here

@houmanka
Copy link
Author

Where should I define that :username method? in the application_controller.rb?

Thanks mate

@Bodacious
Copy link
Owner

No - it's a method that's defined on your model.

It's used in this partial to show who wrote the post

In most cases this would be :username or :full_name but since every app will be different, we give the option to customise which model method is used.

@houmanka
Copy link
Author

NICE,
All done mate.
Thanks again for your help.
Cheers

@nrtechbytes
Copy link

Hi,

I am trying to use blogit in my application.
Done all the bootstrapping as per the README.

Now clicking on /blog, I am also getting the error -
undefined local variable or method `root_path' for #<#<Class:0x007fb20

At the beginning of this issue, it is suggested to uncomment line#82 config.inline_main_app_named_routes = true from config/initializers/blogit.rb

However, it seems the config option inline_main_app_named_routes is no more valid.

Is there any other way to resolve the routing error apart from prefixing all routes with main_app.

Thanks in advance,
NR

@nrtechbytes
Copy link

Pl. ignore the above comment. I was able to resolve my issue with help from this article -
http://candland.net/2012/04/17/rails-routes-used-in-an-isolated-engine/

Thanks

@tbbooher
Copy link

yeah -- same error here . . . maybe this should be in the readme -- i haven't fixed the error yet, but this clearly happens with rails defaults set

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

5 participants