Spina CMS routes set default landing page - ruby-on-rails

I have Rails app that uses Spina CMS,
I want the landing page \ to be one of the pages in admin.
for ex. localhost:3000\home is my localhost:3000
currently getting 404 setting root :to => 'pages#home'
Seems root :to ... is getting overriden by Spina routes
routes.rb
Rails.application.routes.draw do
match '(*any)', to: redirect(subdomain: ''), via: :all, constraints: {subdomain: 'www'}
mount Spina::Engine => '/'
root :to => 'pages#home' # => not working...
get '/*id' => 'pages#show', as: "page", controller: 'pages', constraints: lambda { |request|
!(request.env['PATH_INFO'].starts_with?('/rails/') || request.env['PATH_INFO'].starts_with?("/#{Spina.config.backend_path}") || request.env['PATH_INFO'].starts_with?('/attachments/'))
}
end

In the route page replace root :to => 'pages#home' to root 'pages#home'
and add
resources :pages
Let me know if this works for you :)

Related

Rails "redirect_to" Nested routes with latest model

In my rails app I have two models nested,
Gameround > currentplayer
Gameround is shown on play.html.erb, I also make the currentplayers there. When the currentplayer is made I want to redirect the user to currentplayer#show but I can't seem to figure out the way to route the link. I've tried everything I can think of.
So I need a link that says:
Get url to thiscurrentGameround/ThiscurrentplayerIjustmade
My controller:
def createPlayerforUser
#latest_game_round = Gameround.order(created_at: :desc).first
#currentplayer = #latest_game_round.currentplayers.create({
log_id: #current_user.id
});
if #currentplayer.save
redirect_to url_for([#gameround, #currentplayer])
end
end
config.routes
resources :gamerounds do
resources :currentplayers
end
resources :gamesessions
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# Artikkel, Alien liste
resources :expansions do
resources :aliens
end
resources :users
# You can have the root of your site routed with "root"
#root 'gamesessions#play'
root 'gamesessions#new'
#root 'application#show'
#root 'public#index'
get "signup", :to => "users#new"
get "login", :to => "sessions#login"
post "login_attempt", :to => "sessions#login_attempt"
get "logout", :to => "sessions#logout"
get "profile", :to => "sessions#profile"
get "setting", :to => "sessions#setting"
get "play", :to => "gamesessions#play"
get "wait", :to => "gamesessions#wait"
get "aliens", :to => "aliens#index"
If you run rake routes in the terminal, your list of routes should include one for showing currentplayer. You should be able to use
redirect_to gameround_currentplayer_url(#latest_game_round, #current_player)

Rails 4 static subdomain

I can't set root path for subdomain.
This is my routes.rb part:
constraints subdomain: 'blog' do
scope :module => "blog", :as => "blog" do
resources :posts
end
end
root 'statics#index'
When I am visiting blog.example.com I've got static#index action response and get posts#index, when visiting blog.example.com/posts.
I want to set root path for blog.example.com pointing to posts#index.
No effect for this:
match '/' => 'posts#index', :constraints => { :subdomain => 'blog' }, via: [:get]
I believe you should still be able to call root within the constraints block:
constraints subdomain: 'blog' do
root :to => 'posts#index' # Perhaps this needs to be `blog/posts#index`?
scope :module => "blog", :as => "blog" do
resources :posts
end
end
root 'statics#index'
This works for me with separate namespaces for each subdomain.

Dealing with multiple root paths and scopes in Rails

We have the following routes setup:
MyApp::Application.routes.draw do
scope "/:locale" do
...other routes
root :to => 'home#index'
end
root :to => 'application#detect_language'
end
Which gives us this:
root /:locale(.:format) home#index
root / application#detect_language
which is fine.
However, when we want to generate a route with the locale we hitting trouble:
root_path generates / which is correct.
root_path(:locale => :en) generates /?locale=en which is undesirable - we want /en
So, question is, is this possible and how so?
root method is used by default to define the top level / route.
So, you are defining the same route twice, causing the second definition to override the first!
Here is the definition of root method:
def root(options = {})
options = { :to => options } if options.is_a?(String)
match '/', { :as => :root, :via => :get }.merge(options)
end
It is clear that it uses :root as the named route.
If you want to use the root method just override the needed params.
E.g.
scope "/:locale" do
...other routes
root :to => 'home#index', :as => :root_with_locale
end
root :to => 'application#detect_language'
and call this as:
root_with_locale_path(:locale => :en)
So, this is not a bug!

rails 3.2 link a subdomain to a controller?

Update: rewritten question a bit. Trying to route my subdomains like below
login.app.ltd
user1.app.ltd
user2.app.ltd
signup.app.ltd
Using
Rails 3.2
Devise
To no avail tried several tutorials blog posts, anyone knows a working example for this?
Really stuck on this :(
this is my routes now:
match '', to: 'frontend#index', constraints: lambda { |r| r.subdomain.present? && ( r.subdomain != 'www') }
#match '' => 'home#index', :constraints => { :subdomain => 'login' }
constraints :subdomain => /^(?!signup\b)(\w+)/ do
root :to => "frontend#index"
end
root :to => "frontend#index"
My RailsApps project offers a complete example app showing how to use subdomains:
Rails Tutorial for Subdomains with Devise
Did you take a look at that?
config/routes.rb
devise_for :users
resources :users, :only => :show
constraints(Subdomain) do
match '/' => 'profiles#show'
end
root :to => "home#index"
lib/subdomain.rb
class Subdomain
def self.matches?(request)
case request.subdomain
when 'www', '', nil
false
else
true
end
end
end
Ok with some help managed to get it working
One should do:
constraints subdomain: 'login' do
devise_scope :user do
root to: 'sessions#new'
end
end

Adding Routes to Rails' Spree E-Commerce

I just recently upgraded to 1.0.3, and the routes.rb file in my config/routes folder seems to ignore all my custom routes.
MY routes.rb
JollyStore::Application.routes.draw do
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'
root :to => 'pages#index'
namespace :admin do
resources :wysiwygs
end
match 'about_us/', :to => "pages#about_us"
match 'services/', :to => "pages#services"
match 'raw_resources/', :to => "pages#raw_resources"
match 'contact_us/', :to => "pages#contact_us"
match 'privacy_policy/', :to => "pages#privacy_policy"
match 'return_policy/', :to => "pages#return_policy"
match 'refund_policy/', :to => "pages#refund_policy"
match 'cancellation_policy/', :to => "pages#cancellation_policy"
match 'delivery_shipping_policy/', :to => "pages#delivery_shipping_policy"
end
If I run bundle exec rake routes, it returns all the approriate routes. But when I try to reach that specific page, I get :
undefined local variable or method `about_us_path'
Or the same error for every link that is within my custom routes. Somehow my routes are being ignored. Does anyone know a way to circumvent this issue?
I encountered the same error and found this solution, which solved it by prefixing main_app, before each of my_paths/_urls. In my case, these were links used in one of the /override.rb files.
So, try: main_app.about_us_path.
You can add new routes in the Spree using following block in routes.rb file
Spree::Core::Engine.routes.prepend do
# Your new routes
end
For me prepend did not work.
for me draw did the work:
Spree::Core::Engine.routes.draw do
resources :orders, except: [:new, :create, :destroy] do
post :my_order, on: :collection
end
end

Resources