How to change default landing page in Redmine 3.x? - ruby-on-rails

The older methods for Redmin 2.x suggested to change routes.rb to the follwing:
root :to => 'wiki#show', :project_id => 'myproject', as => 'home'
match '/', :to => 'welcome#index', :as => 'home'
in place of
root :to => 'welcome#index', :as => 'home'
However, this is giving a server error (500), hinting that 3.x needs a different hack to achieve this.
Any Redmine/Rails experts with solutions?

For redmine 3.2.0, it's in the file config/routes.rb, replace
root :to => 'welcome#index', :as => 'home'
by this line for the homepage of a project
root :to => 'projects#show', :id => '<myproject>', :as => 'home'
or by this line for the wiki of a project
root :to => 'wiki#show', :project_id =>'<myproject>' ,:as => 'home'
<myproject> is the identifier of your project, you can see it in the settings page of the project and in the URLs.

example: </br>
root :to => 'my', :action => 'index', :via => :get, :as => 'home'

Related

rails translated paths example

routes.rb
match "about/how_it_works" => "about#how_it_works", :as => "about_how_it_works", :via => :get
match "about/we_are" => "about#we_are", :as => "about_we_are", :via => :get
match "about/what_is" => "about#what_is", :as => "about_what_is", :via => :get
I read this rails guide and changed my code.
new routes.rb
scope(path_names: { about_we_are: 'translated-about-we-are', about_what_is: 'translated-about-what-is' }) do
resources :about, path: 'translated-about'
end
But when I enter localhost:3000/about/translated-about-we-are, I encounter no route matches error.Do you know how can handle with this problem?
Since you've specified path for resources about your path becomes translated-about/.... So you need to use:
http://localhost:3000/translated-about/translated-about-we-are
then you should not get the error.
You can check all the routes generated by issuing rake routes from within your application directory.

What is the best way to reassign routes

Currently I have these routes in my routes.rb file:
get 'exit' => 'sessions#destroy', :as => 'logout'
get 'enter' => 'sessions#new', :as => '
get 'register' => 'users#new', :as => '
get 'posts' => 'posts#new', :as => '
get 'offers' => 'offers#index', :as => 'offers'
Since Forem (https://github.com/radar/forem) is asking me: # We ask that you don't use the :as option here, as Forem relies on it being the default of 'forem'.
What is the best way to refactor my routes, so they would match Forem requests, to avoid using :as?
Maybe this helps: match 'name_you_want' => redirect('ControllerName#action_name')

Creating folder structure using high_voltage gem in Rails

I'm trying to use the high_voltage gem to serve static pages in my Rails app. What I want is for individual sections to get their own folder, but can't quite get it to work & can't find a solution around the web.
What I want:
RAILS_ROOT/app/views/pages/(page) to be routed as '/(page)'
While RAILS_ROOT/app/views/pages/(directory)/(page) => '/(directory)/(page)'
Here's my attempt:
routes.rb:
Cam4::Application.routes.draw do
root :to => 'high_voltage/pages#show', :id => 'index'
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
scope "ruby" do
match '/ruby/:id' => 'high_voltage/pages/ruby#show', :as => :static, :via => :get
end
end
Thanks a lot,
Cameron
Actually ended up solving the problem on my own using route globbing.
Given a Rails 3.2.5 app running high_voltage, with view paths:
RAILS_ROOT/app/views/pages/id [=> '/pages/id' or just '/id']
RAILS_ROOT/app/views/pages/ruby/id [=> 'pages/ruby/id' or 'ruby/id']
Routes.rb:
Cam4::Application.routes.draw do
root :to => 'high_voltage/pages#show', :id => 'index'
match '/*id' => 'high_voltage/pages#show', :as => :static, :via => :get
end

How do I update routes from Rails 2 to Rails 3?

Here are some routes I have in Rails 2 and want to upgrade to Rails 3:
map.callback "/auth/:provider/callback", :controller => "authorizations", :action => "create" #omniauth
map.failure "/auth/failure", :controller => "authorizations", :action => "failure" #omniauth
map.signup 'signup', :controller => 'users', :action => 'new'
map.signin 'signin', :controller => 'user_sessions', :action => 'new'
map.signout 'signout', :controller => 'user_sessions', :action => 'destroy'
match "/auth/:provider/callback" => "authorizations#create", :as => :callback
match "/auth/failure" => "authorizations#failure", :as => :failure
match "signup" => "users#new", :as => :signup
match "signin" => "user_sessions#new", :as => :signin
match "signout" => "user_sessions#destroy", :as => :signout
That should get you going.
I would definitely checkout the screencast that apneadiving mentioned as well as Rails' take on routes.
Take a look at the rails_upgrade plugin at https://github.com/rails/rails_upgrade and its rake rails:upgrade:routes.
script/plugin install git://github.com/rails/rails_upgrade.git
rake rails:upgrade:routes
This will take your current routes file and rewrites it using the Rails 3 syntax. Copy the console output and look for any potential optimizations after you've read through the documentation in some of the other answers.
This should answer and make you learn:
http://railscasts.com/episodes/203-routing-in-rails-3
You may also find lots of great information at the Rails Routing from the Outside In.

How do you make the root_url one level above the root/ and still keep the routes intact

I have a working application with proper routes.
The application then became shared with another application with a homepage below the two sites.
-- Root Homepage --
/ \
| |
Website 1 Website 2
Now when I go to my page, the site loads. But the functioning does not.
My Routes
match '/generate_csv/(:id)', :to => "main#generate_csv", :via => :post, :as => "generate_csv"
resources :main
root :to => 'main#new'
Currently, my application is prepended by rails/website_1
How can I get my routes to line up again?
UPDATE
So this resolves the #create method, but I am still trying to get that first match route working..
scope "rails" do
resources :main
match 'main/generate_csv/(:id)', :to => "main#generate_csv", :via => :post, :as => "generate_csv"
end
The problem is solved by writing the routes twice. This can't be right:
scope "rails" do
resources :main
match 'main/generate_csv/(:id)', :to => "main#generate_csv", :via => :post, :as => "generate_csv"
end
resources :main
match 'main/generate_csv/(:id)', :to => "main#generate_csv", :via => :post, :as => "generate_csv"
root :to => 'main#new'
It might be easier to use a subdomain as an alternative when merging two separate sites by doing something like:
constraints(:subdomain => /website1/) do
match '/' => 'website2/dashboard#index'
end
Otherwise, maybe try a scope:
scope module => "website1" do
resources :main
end

Resources