i want to extend the UserController with an setEventManager implementation, to display another layout - just with an login mask.
When i call the url www.example.com i get my Controller, with the other layout.
But if type in a wrong username, i redirected to www.exmpale.com/user/login and i get the default layout.
How i can overwrite all routes from ZfcUser Module and redirect them to my own controller, to ensure, the UserController can not called directly.
Thank you.
If I understand your question right, you probably just have to edit the file module.config.php. It contains all route definitions.
From how I understand your question you have an own controller called something like MyBetterUserController?
You can add an own module as extension to the ZfcUser module, maybe you want to call it something like ZfcUserMod. This new module will only contain a Module.php file and a folder config with the configuration file.
Then you can define your routes in this module’s configuration file and overwrite all routes from ZfcUser. Make sure that you use the exactly same route names (the keys in the array) as ZfcUser does (currently they use zfcuser as route name). Otherwise the routes will not be overwriten and the UrlHelper will not use your routes.
Then add ZfcUserMod to the global application.config.php after ZfcUser.
Wouldn't it be easier to override just the controllers -> invocables pointing 'zfcuser' => 'namespace\your\extendedusercontroller' instead of rewriting all the routes ?
Related
I have the following routes:
create_admin_path GET /app/views/createAdmin/create_admin.html.erb(.:format) application#createAdmin
I have this in routes.rb
get "/app/views/createAdmin/create_admin.html.erb", to: "application#createAdmin", as: "create_admin"
I have this in the application_controller.rb
def createAdmin
end
and in the view I have a folder called createAdmin which has a file called create_admin.html.erb
in the create_admin.html.erb I have something like this:
<h1> testing is here </h1>
Yet I am receiving this error message:
No route matches [GET] "/app/views/create_admin/create_admin.html.erb"
What am I doing wrong ?
Thanks for your time
The views must match in controller name and view file name, that's if you're registering the route to application#createAdmin, then the folder must be application/ and the file createAdmin, in camel case as you've named the action and the route, so your file must be called createAdmin and must be located in a folder called application/.
/app/views/application/createAdmin.html.erb.
But, there are some things to add:
There's no need to use the ApplicationController to handle such operations, you can easily create a new controller and use it with that purpose instead polluting the ApplicationController.
You don't need to specify the full route to the view as the URI when registering a route, unless it's that specifically what want to do.
When working with Ruby use snake case.
I have a messy rails 3 application that's come from a different developer and I need to refactor it.
What I want to do is move the contents of "app" into a subfolder called "classic".
app/classic
And then have all URL's with a classic prefix such as
localhost:3000/classic/wills/new
Route to controllers inside of the "app/classic" folder.
And then every regular url that does not contain the classic prefix - route in the standard way to app/
Is it possible to do this? The only thing I've discovered so far is that I can add a scope inside of my routes file.
scope(:path => '/classic')
But all that does is require a prefix for every URL. I'm really not sure how to go about this!
This is a route namespace. Take a look at this section in Rails Routing from the Outside In: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
namespace :classic do
# your routes here
end
This will do 3 things -
the path to the controller files need to be under /app/controllers/classic/
the name of the controllers need to change to Classic::ControllerName
the url is now /classic/controller/action
This sounds like what you want, but you can modify this to get just the parts you want if you don't want all 3.
In route.rb file:
#Of course, you have to configure the right http method.
get 'wills/new' => 'wills#new', as: 'to_classic_wills_new'
Hope this helps!
I would like to know how to access engine routes by using Rails.application.routes.url_helpers.
I have a factory object that creates a string including a dynamically generated url. Currently, I can generate urls by using Rails.application.routes.url_helpers.(INSERT PATH NAME).
However, it can only access the routes in the main app. I cannot access the routes of engines mounted on the main app.
Things I have tried
I've tried to use Rails.application.routes.engine_name where engine_name is the name under which the engine is mounted on the main app.
I've tried to use MyEngine::Engine.routes.url_helpers to access the routes in the Engine. It works, but I would like to use Rails.application.routes.url_helpers because there are many factory objects like this one, and they are all inheriting from the superclass that delgates url_helper to Rails.application.routes.
Any suggestions? Let me know if any clarification is needed.
You have to use engine route proxy method.
From your example call the url helper using the following syntax as example:
my_engine_engine.articles_path
To rename the proxy method helper, just edit the routes config file inside your rails application:
mount MyEngine::Engine => '/app', :as => 'my_engine'
so you can now call the previous example:
my_engine.articles_path
Assuming that your engine namespace is EngineName, it should be:
EngineName::Engine.routes.url_helpers.some_engine_path
How can I create a simple testing/experimenting file in grails? I tried creating a TestController.groovy file in the /controllers folder, and then tried going to /project/Test/ but I get a 404.
In my TestController.groovy:
package aust
class TestController {
def index = {
render {'Winning!... finally'}
}
}
If you create a TextController and go to /project/Test/ then there is an issue.
------------------------------------------^-^
go to
/project/text/
the url needs to match the name of the controller -- remember Grails is all about convention over configuration.
Also, make sure you have a default action on the controller, and any necessary gsps.
Have you setup a route to it correctly in your routing file? Also, you need to create an action in your controller, like index. Then, you should create a View in the Views folder, like text\index.gsp. I am a newbie too, but the documentation is great for Grails. Good luck.
I'm tired of creating a new line in my routes.rb every time I add a new method in my controller. Is there a way in routes.rb to tell rails to accept any defined action in a given controller? I'm pretty sure I've done this before but can't remember how. I still need to explicitly specify the controller, however, because many other people use this routes file.
Thanks!
This is from the default generated config/routes.rb file
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'