I'm just starting out with Rails and I decided to try out ActiveAdmin last night. I was able to register a new resource name 'Pages' in my ActiveAdmin app, but there's one thing I can't figure out how to customize with it.
I create a new Page with ActiveAdmin, but it's published within the admin/.. path.
(e.g. mydomain/admin/page/1)
How do I change the routing so the page can be viewed at mydomain/page/1?
Are you able to change the routing of existing resources in ActiveAdmin?
I'm very new at Rails so I assume this is a pretty easy fix. I plan to run through some more tutorials/books so I can better understand routing.
You can change the default admin namespace.
To do so you have to go to config/initializers/active_admin.rb file and find the following configuration:
# Default:
# config.default_namespace = :admin
Uncomment the line and set the default_namespace to whatever you need.
However, if you need to turn off the namespace at all, you will have to set the default_namespace to false:
config.default_namespace = false
This will allow you to run the AA from the root.
By doing so be aware of changes in routes:
if changed the namespace to hello, the admin_games_path becomes hello_games_path;
if changed to no namespace, use normal routes: admin_games_path becomes games_path.
Related
Just wanted to know, what does this line mean in the routes.rb file:
AppName::Application.routes.draw do
Please explain. I am new to Rails.
Have a read through this page.
Basically, within the block passed to Application.routes.draw (which is just a call to a method defined in ActionDispatch::Routing module within the Rails core framework), you define all the URLs/Paths that you want your Rails application to respond to.
You can see all these route definitions, by running:
rake routes
in your terminal.
It is the main routes file which defines the root and other paths for the link.
It is used as suppose you want to change your index page from default ruby on rails to your index page you make changes to file and add
root to: "controllername#index"
This file is also used to add the model to the application
resources: "model_name"
Apart from this you can also define links in your rails application
get 'courses/index'
So going from courses controller to view of the index.
I'm creating an engine that needs to insert some routes into the application's router. For this particular gem, I'd rather not application's routes.rb if possible. Is there a way to insert routes at a particular location in the router via code? I'm looking for an API that does something like:
Rails.application.routes.insert("resources :foos", :before => "some string in routes.rb")
If I create a config/routes.rb inside the engine and define some routes, this kind of works. Rails is smart enough to mix the engine's routes into the application's routes, but it tacks them on at the end of the route list. I need them to appear at the beginning so the engine's routes take priority.
I'm aware that I can namespace the routes by mounting the engine in the application's routes.rb, but this creates a routing structure that I don't really want. I want the engine's routes to look they are a part of the application by defining some routes in the actual application.
I have a workaround which is to add the following to the application's routes.rb.
Rails.application.routes.draw do
MyEngine.setup_routes(self)
#...other routes below
end
MyEngine.setup_routes looks like
def self.setup_routes(map)
map.get 'a_path', :to => 'a_controller#a_path'
end
This at least allows me to control the point where the routes get defined in the application's route list, but the user still has to manually update his routes.rb (or I have to build an installer that does it). It seems like there should be a way to tell rails to tack some routes onto the start of the route list...
All. I've googled this quite a bit and I haven't found anything that'll work.
I want to change the admin route to something other than "admin". In this case, we'll just use "customadmin" as the desired name.
I've been toying with two solutions. One uses rewrites with Nginx, the other uses the routes in the spree application. Maybe, I should use both.
I'm doing this for the SSL layer, so in my 443 server section, (for the Nginx Solution) I tried the following:
locaton /customadmin/
{
rewrite ^/customadmin/(.*)$ /admin/$1 permanent;
}
Cool. That maps customadmin to all the admin routes. But What I don't want is for any random user to even get to the /admin section. Also, If I'm mapping 'customadmin' to 'admin' it'll probably create some sort of error.
Ideas:
*Should I use the 'internal' property? That is, in the admin location block, only go somewhere if the request is internal (or from a rewrite)
*Is there a way to namespace /admin in my spree application so that it uses 'customadmin' instead? I know it can be done (somewhat) by doing the following:
Spree::Core::Engine.routes.append do
scope :customadmin do
namespace :admin do
resources :my_model
resources :my_other_model
end
end
end
Environment Specs:
Spree: 2.1.2
Ruby: ruby-2.0.0-p353
rails: 4
I am new to Ruby on Rails and have some problems.
For the development I use RubyMine IDE, I manage to create models, controllers and views, but I have problems with the routing. By default, routes.rb file contains only this method Apis::Application.routes.draw do with an empty body.
For example, I create a controller TestController, then the index method and in routes.rb I add this instruction resources :test. So far, it works fine. But if I add another method, let's say method1 (and the view) I can't reach it in a browser http://localhost:3000/test/method1.
What else should I add in routes.rb file?
Is there any way to make the routing automatically from the IDE, with less editing the routes file?
resources :test
is a resourceful route which provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to particular CRUD operations in a database
you can uncomment in your routes to enable the controller action mapping.
match ':controller(/:action(/:id(.:format)))'
or use -
match "/test/method1" => "test#method1"
Detailed routes info # http://guides.rubyonrails.org/routing.html
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)))'