Hi, I''m new to Ruby/RoR so please bare with me! I''m trying to adapt a ruby setup where someone logs in to a bonjour service via a web browser. I have the login screen which asks for host and password. There is only one user per host and i can log in fine. It''s suppose to redirect me to /list in my browser but doesn''t. Once i''ve entered the correct login credentials and manually add /list to the address i can see what i want. So the login seems to work, it just doesn''t redirect me. I need it to redirect me though when the login is successful. The part i believe i need to edit; class JobController < ApplicationController before_filter :verify_login, :except => [:index, :login_to_engine] before_filter :engine, :except => [:index, :login_to_engine] def verify_login unless session[:engine_host] redirect_to :controller => ''job'', :action => ''index'' return false end return true end which is in my controllers directory. Any help appreciated! -- Posted via http://www.ruby-forum.com/.
Hi> def verify_login > unless session[:engine_host] > redirect_to :controller => ''job'', :action => ''index'' > return false > end > > return true > endCan u change it to def verify_login unless session[:engine_host] redirect_to :controller => ''job'', :action => ''index'' and return false end return true end Sijo -- Posted via http://www.ruby-forum.com/.
redirect_to :controller => ''job'', :action => ''index'' and return false -- Posted via http://www.ruby-forum.com/.
Sijo Kg wrote:> redirect_to :controller => ''job'', :action => ''index'' and return falsewhat file should this be in? my ApplicationController of JobController? I tried it individually in both, but to no avail... Thanks for the speedy response! -- Posted via http://www.ruby-forum.com/.
Hi If it is needed by more controllers not only jobs controller you can move it to application.rb and the filter too..Does it call the filter? Sijo -- Posted via http://www.ruby-forum.com/.
Sijo Kg wrote:> Hi > If it is needed by more controllers not only jobs controller you can > move it to application.rb and the filter too..Does it call the filter? > > Sijothe before_filter only appears in the job controller. this is what i have: #------------------------------# # application_controller.rb # #------------------------------# class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password def verify_login unless session[:engine_host] logger.debug "no engine host in session, redirecting to job/index" redirect_to :controller => ''job'', :action => ''index'' return false end return true end end #-----------------------------------# # job_controller.rb (1st 21 lines) # #-----------------------------------# class JobController < ApplicationController before_filter :verify_login, :except => [:index, :login_to_engine] before_filter :engine, :except => [:index, :login_to_engine] def verify_login unless session[:engine_host] redirect_to :controller => ''job'', :action => ''index'' return false end return true end def index end def list end def view @job = engine.getJobForID(params[:id]) end And i''m sorry but i don''t understand your question about the filter (i am VERY VERY new to RoR!) Thanks for your patience :) -- Posted via http://www.ruby-forum.com/.
Hi Please do like Application controller as it is class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password def verify_login unless session[:engine_host] logger.debug "no engine host in session, redirecting to job/index" redirect_to :controller => ''job'', :action => ''index'' return false end return true end end In jobs controller you dont need verify_login So class JobController < ApplicationController before_filter :verify_login, :except => [:index, :login_to_engine] before_filter :engine, :except => [:index, :login_to_engine] end Sijo -- Posted via http://www.ruby-forum.com/.
Sijo Kg wrote:> Hi > Please do like > Application controller as it is > > class ApplicationController < ActionController::Base > helper :all # include all helpers, all the time > protect_from_forgery # See ActionController::RequestForgeryProtection > for details > > # Scrub sensitive parameters from your log > # filter_parameter_logging :password > > def verify_login > unless session[:engine_host] > logger.debug "no engine host in session, redirecting to job/index" > redirect_to :controller => ''job'', :action => ''index'' > return false > end > return true > end > end > > In jobs controller you dont need verify_login So > > class JobController < ApplicationController > before_filter :verify_login, :except => [:index, :login_to_engine] > before_filter :engine, :except => [:index, :login_to_engine] > > end > > > > > SijoSijo, This STILL doesn''t work. Could it be because nowhere in here have i told it where to redirect to? Can i add an IF statement to the def verify_login in the application controller? Thanks for your help so far! Dan -- Posted via http://www.ruby-forum.com/.
Hi And what is wrong now? Did you ensure if session[:engine_host] is not set it enters to unless session[:engine_host].....end For example write some puts inside unless session[:engine_host]......end And check if that happens according to what you specify Sijo -- Posted via http://www.ruby-forum.com/.
Sijo Kg wrote:> Hi > And what is wrong now? Did you ensure if session[:engine_host] is not > set it enters to unless session[:engine_host].....end > For example write some puts inside unless > session[:engine_host]......end > > And check if that happens according to what you specify > > > SijoSijo, my apologies, it looks like i wasn''t looking at the right part of the script (this is how new i am to RoR!) So, i found the part in the script which tells you about the login redirection... a = @e.getSettingsInGroupAtPath("/") # render :update do |page| # if a.size > 0 # # page.replace_html(''logo_text'', :partial => ''logo_text'') # # # page.replace_html(''toggle_app_box'', :partial => ''toggle_box_content'') # # page.replace_html(''loginout_links_content'', :partial => ''loginout_links_content'') # # page.visual_effect(:toggle_blind, ''login_content'', :duration => 0.5) # # # page.replace_html(''submit_job_box'', :partial => ''submit_job'') # # page.show(''submit_job_box'') # # page.show(''spinner'') # # page.replace_html(''all_states'', :partial => ''all_states'') # # page.replace_html(''error_msg'', '''') # # page.call(''autoInit_trees'') # else # page[''engine_password''].visual_effect(:highlight, :duration => 3) # flash[:error] = "wrong password" # # page.alert flash[:error] # page.replace_html(''error_msg'', flash[:error]) # render :nothing => true, :status => 401 # end # end if a.size > 0 puts "logged in" session[:engine] = @e else reset_session puts "not logged in. reseting session." end redirect_to :controller => ''job'', :action => ''list'' end def logout reset_session redirect_to :controller => "job", :action => "index" end end but when i uncomment all of the commented parts, i get a double render/redirect error.... -- Posted via http://www.ruby-forum.com/.
Hi There you have to use and return as I said earlier.. Please read 2.2.13 Avoiding Double Render Errors from http://guides.rubyonrails.org/layouts_and_rendering.html Sijo -- Posted via http://www.ruby-forum.com/.
Sijo Kg wrote:> Hi > > There you have to use > > and return > > as I said earlier.. > Please read 2.2.13 Avoiding Double Render Errors from > http://guides.rubyonrails.org/layouts_and_rendering.html > > SijoIt still doesn''t work!! It says that it''s redirected in Terminal, but it doesn''t redirect my HTML (web browser)... I''ve done all that you have said, but nothing is working :( Dan -- Posted via http://www.ruby-forum.com/.
Dan Sinclair wrote:> Sijo Kg wrote: >> Hi >> >> There you have to use >> >> and return >> >> as I said earlier.. >> Please read 2.2.13 Avoiding Double Render Errors from >> http://guides.rubyonrails.org/layouts_and_rendering.html >> >> Sijo > > It still doesn''t work!! > > It says that it''s redirected in Terminal, but it doesn''t redirect my > HTML (web browser)... > > I''ve done all that you have said, but nothing is working :( > > DanOk, so i think i''ve narrowed it down to where i think i need to change/add code... In my job_controller.rb file, i have: def list end so could this be the problem, as i haven''t told it to "point" anywhere? If so, what would i add to define this as a different webpage? Dan -- Posted via http://www.ruby-forum.com/.