search for: helper_method

Displaying 20 results from an estimated 56 matches for "helper_method".

2009 Jun 05
6
rails 2.3.2
...gged_in_user = User.find(session[:user]) if session[:user] end def logged_in_user return @logged_in_user if is_logged_in? end def logged_in_user=(user) if !user.nil? session[:user] = user.id @logged_in_user = user end end def self.included(base) base.send :helper_method, :is_logged_in?, :is_admin?, :logged_in_user end end This does work under RAILS 2.1.1, but not under 2.3.2 It says: undefined method `is_logged_in?'' for #<ActionView::Base:0x78cf044> Cheers P. -- Posted via http://www.ruby-forum.com/.
2005 Mar 10
8
Login controller additions
I have added roles and roles_users table and updated the model so that my users can have multiple roles. ("Admin" role does always have id = 1). I have added these methods to my application controller. <code> helper_method :is_admin? helper_method :is_user? def is_admin? if @session[''user''] @session[''user''].roles.find(1) else false end end def is_user? !@session[''user''].nil? end </code> The problem is t...
2008 Nov 10
3
to_xml and helper methods
Hi, I have an array with objects and I want to generate an XML like: <objects> <object> <category_id>1</category_id> <helper-method>result 1</helper-method> </object> <object> <category_id>2</category_id> <helper-method>result 2</helper-method> </object> </objects> The helper
2008 Jun 13
3
before_filter order of execution
...er than 2 can view specific objects. My code is: ----------------------------------------------------------- IN USER_CONTROLLER before_filter :login_required before_filter :access_granted, :only => [:destroy, :new , :edit] IN APPLICATION.RB def logged_in? ! @current_user.blank? end helper_method :logged_in? def login_required return true if logged_in? session[:return_to] = request.request_uri redirect_to :controller => "/account", :action => "login" and return false end def access_granted if @current_user.blank? return false else...
2006 Mar 27
3
Define methods for controllers, helper AND models?
Hi all I know that I can define methods in e.g. the application controller and make them available to the helpers using helper_method(), but how can I make them available in the models? I have for example the following method, that I want to be able to call from any model I wish... def ApplicationController helper_method :member def member session[:member] end end Thanks for any help. :-) Joshua -- Posted via ht...
2006 Jun 27
6
embedding ruby code in a [flash :notice]
The ruby code in this isn''t evaluated... flash[:notice] = "Your last recorded entry was <%= @in_out.time_in %> <br />You are currently marked as ''In'', you probably want to check ''Out''" Is there a way? Craig
2006 Jun 24
7
Newbie Q: "user" variable in every view?
Newbie to RoR -- as a long time Java Struts/etc. guy it is an awesome tool! I have implemented some basic login/session stuff with the help of a great tutorial, props to the author ( http://www.aidanf.net/rails_user_authentication_tutorial). I have a trivial instance method in ApplicationController, which just grabs the User object from the session. def current_user session[:user] end
2006 May 31
5
undefined method `redirect_to''
Hi all I have followed this tute: http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger to get rails running and all is fine except for getting: undefined method `redirect_to'' when I load my test page. I have the following in my xx.rhtml: <%= select :group, :user_id, find_all_groups, {}, {:onclick => select_group, :size => find_all_groups.size + 1}
2006 Jun 27
5
Can''t call public application.rb method from ERb template
All, I have a left navigation partial that I want to dynamically generate CSS classes for based on the current controller action. In my ERb template, I have <DIV class="<%= get_menu_display_style(''login_form'') %>"> In application.rb, I have the method get_menu_display_style defined as: public def get_menu_display_style(action_requested)
2011 Apr 05
4
Rails 3.0.5 gives SQLite3::SQLException for the same code that works on 3.0.3
Hello, I recently updated Rails to 3.0.5. The very same code that worked on 3.0.3 now gives error. The code is: def kategorialista Kategoria.where(:elfogadva => TRUE).order("nev").collect {|s| [s.nev, s.sefuri]} end It is in application_controller.rb with helper_method :kategorialista The error it gives on 3.0.5: SQLite3::SQLException: no such table: kategoria: SELECT "kategoria".* FROM "kategoria" WHERE "kategoria"."elfogadva" = ''t'' ORDER BY nev Obviously there is no such table as kategoria, but there i...
2007 Dec 05
4
render :update and controller private methods
Probably asked and answered, but... Why are controller private methods inaccessible inside the block passed to render :update ? This does not work: class MyController < ApplicationController def some_action render :update do |page| page.replace_html ''an_element'', some_private_method end end private def some_private_method return
2011 Jun 09
8
Fail to call
Hi, I''m trying create a user system for a future project but I have a problem when I want give to my users the "Welcome". This is my code: #application_controller class ApplicationController < ActionController::Base protect_from_forgery helper_method :current_user private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user @current_user = current_user_session && current_user_session.user end end #welcome_controller c...
2006 Jun 28
0
Getting name of currently rendering ERb template in view?
If I''m writing code in a template and I want to refer to the name of the template itself so that I can pass it to a helper method, is there a built-in variable (like controller_name or action_name) that I can use. Assume x.rhtml and in this template I have helper_method(). I want to pass "x.rhtml" into helper_method without hardcoding it. Do I have access to the _currently rendering_ template name? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
2006 May 02
1
Sharing function between helper and controller
Hi, I have a utility function repeated in both my helper and my controller. Not DRY. I have this repetition because other functions in the helper and in the controller both use the utility function. Where do I put this function so that both the helper and controller can access the function? Mayber there is a different solution? Thanks, Peter
2006 May 08
3
MVC newbie question
All, Is it possible for a view to call back to a controller method? If so, what is the syntax? === details I have a list view that I want to filter out inactive rows based on several table fields being zero, old, etc. It would seem I should create a "filtered" method in the controller (which I have done). Then invoke if from the view like: for row in @rows continue if row.filtered
2005 Dec 19
1
Application.rb / Application_Helper.rb / DRY help
Hi all, I have defined the following method in both application.rb and application_helper.rb: def still_logged_in? !session[:user_id].nil? end This method is called in a before_filter in my application.rb, as well as in my layout/application.rhtml and view/user/login.rhtml (for showing a login / logout button, etc.) I had to put it both places, otherwise I would get an
2005 Dec 19
3
Where to put code - app controller, or app helper?
I have a function i want to be used in both views and controllers: def year_to_fiscal_year(year) # converts, say, an integer 2003 into ''0304'' year.to_s[2,2] << (year+1).to_s[2,2] end Where should i put it ? -- Posted via http://www.ruby-forum.com/.
2011 Mar 09
1
undefined method `flunk' for #<Spec::Example::ExampleGroup::Subclass_1:0x0000000516bd40>
I''m running into an issue using ONLY rspec version 1.3.3 (no rails / rspec-rails with this project) where i''m hitting the following error: My code looks like this: describe Win32Meterpreter before :all helper_method end def helper_method ## If a session came back, try to interact with it. if @session @session.load_stdapi else flunk "Couldn''t get a session!" end end en...
2005 Oct 12
1
Global helper method?
I want a method to be accessible from everywhere in my app (it''s a Gaussian RNG) - I''ve already put them as protected methods in application.rb but that would only allow them to be accessed from controllers. I have a method in a model that needs access to this too, and I''d prefer not performing the calculations outside the model. Copying the method definition into the
2009 Oct 28
1
Authlogic Page View Authentication Help
Hi: I am a newbie at ROR, and I am grasping my head around Authlogic. I am having hard time trying to figure out how can I do the following: in my application controller I have the following helpers: filter_parameter_logging :password, :password confirmattion helper_method :all private def current_user_session return @current_user_session if defined? (@current_user_session) @current_user_session = UserSession.find end def current_user return @current_user if defined?(@current_user) @current_user = current_user_s...