I have a controller pages as follow:
class PagesController < ApplicationController
def home
end
def about
end
def login
end
end
i have the views corresponding also , and in my routes.rb, i have the following
devise_for :users
get 'log in' => 'pages#login'
get 'about' => 'pages#about'
root :to => 'pages#home'
when i try to go to the login page it's gave me an error :
undefined local variable or method `login_path' for #<#:0x2b9a298>
i try to match the controller to the actions ,same error . i'm new with rails , i'm trying to understand what i did wrong , because it works for the 'about' page. thanks
Your routes should be:
match 'login', :to => "pages#login", :as => :login
match 'about', :to => "pages#about", :as => :about
To learn more about Rails routing, check out the routing guide.
get 'log in' => 'pages#login'
Is there a space in "log in" or is that just how it appears here?
I think Devise also has some special setup in how you customize the routes. Here is an example provided on their GitHub page:
devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
It's at https://github.com/plataformatec/devise under Configuring Routes.
Related
Hi Everyone,
I came across on a problem that I can't really figure out myself, It believe that all your expertise can help me through solving this error I get whenever I try to access a route to add a script. Here is my controller code:
class HomeController < AuthenticatedController
def index
#products = ShopifyAPI::Product.find(:all, :params => {:product_type => "Underarmour"})
# script = ShopifyAPI::ScriptTag.new(:all, :params => {:event => "onload", :src => "https://shopperapproved.herokuapp.com/sajs/14043.js"})
end
def script
ShopifyAPI::ScriptTag.create(:event => "onload", :src => "https://shopperapproved.herokuapp.com/sajs/14043.js")
end
end
and my route file is:
controller :sessions do
get 'login' => :new, :as => :login
post 'login' => :create, :as => :authenticate
get 'auth/shopify/callback' => :callback
get 'logout' => :destroy, :as => :logout
end
root :to => 'home#index'
match "script/",
:to => "home#script",
:via => :get
I want to add a script by accessing this route: on my index view:
<h3>Add your ShopperApproved site ID:</h3>
https://shopperapproved.herokuapp.com/script --> if i am going to click this link i will be redirected to HomeController#script
I hope you can help me..
Have you set up a seesion & token? i fnot you cant create the script in your store
https://github.com/Shopify/shopify_api
I assume you did not set up a session so you cant "connect" to your store.
Verify that you have a valide session and it will work
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'
I've got a Rails 4 app that I'm trying to reconfigure to use subdomains for jobportals. Right now the root path for each portal is /jobportals/:id. What I want is for a user to be able to go to client.example.com and hit that root path. Then for example, if the user edits their profile, the url would be client.example.com/user/edit rather than www.example.com/jobportals/:id/user/edit.
I followed this ASCIIcasts tutorial on setting up subdomain routing, but it's not working for me. When I go to http://client.lvh.me:3000/, I am hitting the root_path of my Rails app, rather than the root_path for the portal.
I think the problem is that Constraints(Subdomain) isn't working with resources :jobportals. How can I reconfigure my routes to accomplish what I'm after?
MyApp::Application.routes.draw do
devise_for :users, :controllers => {:registrations => "registrations"}
root 'general#home'
get '/about' => 'general#about'
get '/team' => 'general#team'
get '/careers' => 'general#careers'
get '/terms' => 'general#terms'
get '/privacy_policy' => 'general#privacy_policy'
constraints(Subdomain) do
resources :jobportals, controller: 'portals/general' do
member do
root 'portals/general#home'
devise_scope :user do
get '/user/sign_in' => 'portals/sessions#new'
post '/user/sign_in' => 'portals/sessions#create'
delete '/user/sign_out' => 'portals/sessions#destroy'
post '/user/password' => 'portals/passwords#create'
get '/user/password/new' => 'portals/passwords#new'
get '/user/password/edit' => 'portals/passwords#edit'
patch '/user/password' => 'portals/passwords#update'
put '/user/password' => 'portals/passwords#update'
post '/user' => 'portals/registrations#create'
get '/user/sign_up' => 'portals/registrations#new'
get '/user/edit' => 'portals/registrations#edit'
patch '/user' => 'portals/registrations#update'
put '/user' => 'portals/registrations#update'
delete '/user' => 'portals/registrations#destroy'
end
get '/jobs' => 'portals/general#jobs'
get '/companies' => 'portals/general#companies'
get '/alljobs' => 'portals/general#alljobs'
resources :applications, controller: 'portals/applications'
get ':id' => 'portals/companies#profile'
get ':id/jobs' => 'portals/companies#jobs'
get ':id/jobfunctions' => 'portals/companies#jobfunctions'
end
end
end
end
Working Code Below
MyApp::Application.routes.draw do
devise_for :users, :controllers => {:registrations => "registrations"}
root 'general#home'
get '/about' => 'general#about'
get '/team' => 'general#team'
get '/careers' => 'general#careers'
get '/terms' => 'general#terms'
get '/privacy_policy' => 'general#privacy_policy'
constraints(Subdomain) do
get '/' => 'portals/general#home'
devise_scope :user do
get '/user/sign_in' => 'portals/sessions#new'
post '/user/sign_in' => 'portals/sessions#create'
delete '/user/sign_out' => 'portals/sessions#destroy'
post '/user/password' => 'portals/passwords#create'
get '/user/password/new' => 'portals/passwords#new'
get '/user/password/edit' => 'portals/passwords#edit'
patch '/user/password' => 'portals/passwords#update'
put '/user/password' => 'portals/passwords#update'
post '/user' => 'portals/registrations#create'
get '/user/sign_up' => 'portals/registrations#new'
get '/user/edit' => 'portals/registrations#edit'
patch '/user' => 'portals/registrations#update'
put '/user' => 'portals/registrations#update'
delete '/user' => 'portals/registrations#destroy'
end
get '/jobs' => 'portals/general#jobs'
get '/companies' => 'portals/general#companies'
get '/alljobs' => 'portals/general#alljobs'
resources :applications, controller: 'portals/applications'
get ':id' => 'portals/companies#profile'
get ':id/jobs' => 'portals/companies#jobs'
get ':id/jobfunctions' => 'portals/companies#jobfunctions'
end
end
It is looking like constraints are not define properly, it is something like get 'jobportals', constraints: {subdomain: 'subdomain_name'}
Checkout the rails guide
I am trying to implement sign up through LinkedIn to the current Devise gem. These are the current routes:
devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret',
:confirmation => 'verification', :unlock => 'unlock', :registration => 'register',
:sign_up => 'signup' }, :controllers => {:omniauth_callbacks => "omniauth_callbacks"}
And the view: = link_to "Sign in with Linkedin",user_omniauth_authorize_path(:linkedin)
Returns to this error:
No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:linkedin, :format=>nil} missing required keys: [:provider]
I've tried to add provider key too, like: = link_to "Sign in with Linkedin",user_omniauth_authorize_path(:provider => 'linkedin')
But then I got:
No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>"linkedin"} missing required keys: [:provider]
What am I missing at this point?
Thank you very much
Add the line in devise.rb
config.omniauth :linkedin, 'APP_ID', 'APP_SECRET'
Devise will automatically add a signin link using linkedin.
In omniauth_callbacks_controller.rb add a method as:-
def linkedin
#code for authorization using linkedin callback credentials
end
I'm a newbie in the Rails, but I can't figure this out.
Rails maps url_for(:controller => 'login', :action => 'check')
to
"/assets?action=check&controller=login"
It should be mapped to /en/login/check (coming from /en/login/index)
My routes.rb:
MyApplication::Application.routes.draw do
scope "(:locale)", :locale => /en|de/ do
resources :login do
get 'index', :on => :member
get 'check', :on => :member
end
end
match ':locale/:controller/:action/:id'
match ':controller/:action/:id'
match ':locale/:controller/:action/:id.:format'
match ':controller/:action/:id.:format'
root :to => 'main#index'
end
I'll read some more about routing, but I'm really confused where /assets comes from and why it's not mapped correctly.
You need to specify the :locale in the url_for helper, else the router won't actually find a match.
url_for(locale: 'en', controller: 'login', action: 'index')