Displaying 20 results from an estimated 10000 matches similar to: "Sharing function between helper and controller"
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/.
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
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
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
2006 Oct 08
3
Call an helper method from a controller
Hello, this have been debated few times in the forum but I didn''t found
a satisfying solution : my problem is very simple, I have few methods
dealing with cookies that are intended to be used in controllers and
views.
Let say I have the read_cookie() method. Because it deals with the
response object putting this method in the /lib directory doesn''t fit
nicely because I
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)
2006 Jan 15
4
model helper location
Hi,
I''m looking at the rails cookbook for uploading files[1]. At the
bottom of the page it says that the sanitize_filename functioin would
probably go in a helper or a library. I wonder where these files would
be or what they would be called. Pehaps there are some conventions I
need to know about?
Thanks,
Peter
[1] http://manuals.rubyonrails.com/read/chapter/78
2006 May 21
3
First try with lighttpd
Hi,
I have a Rails application sitting on my computer that works just fine
with webrick. I would like to try to serve it locally with lighttpd
I followed the instructions on the hivelogic site for installing lighttpd
http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger
Then I looked on page 457 in the Agile Rails book for instructions
about configuring the rails app for
2006 Feb 25
8
linking a .swf file in a rails document
Hi,
I have a little .swf movie I''d like to have in my page. Is there a
rails way of linking it?
Thanks,
Peter
2013 Oct 17
4
MusicOnHold starts magically for no reason
Dear list,
on Asterisk 1.4.21 which is being used in a callthrough scenario -
callers call via PSTN to a DID coming in via SIP and then dialing
outbound via DTMF and the outbound calls get routed via some SIP
termination provider - lately I see that every now and then MusicOnHold
gets triggered like this on outbound calls:
Started music on hold, class 'default', on
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
2009 Jun 05
6
rails 2.3.2
Hi all,
I am using rails v.2.3.2 and if I put following line to my
ApplicationController:
include LoginSystem
and I moved my login_system.rb to lib folder:
module LoginSystem
protected
def is_logged_in?
@logged_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
2007 Jul 17
2
acts_as_ferret 0.4.1
Hi folks,
I just released version 0.4.1 fixing several bugs and bringing the
DRb server''s index versioning feature to the stable branch.
Please see [1] for more changes.
Cheers,
Jens
[1] http://projects.jkraemer.net/acts_as_ferret/query?status=closed&milestone=0.4.1
--
Jens Kr?mer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/ - The new free film database
2006 May 05
3
Best place for storing configuration information?
Hi all,
Where do you store your non-Rails-specific configuration info? For
instance, I want to be able to login to LDAP as a particular admin
user. I don''t want the u/p combo in any of the models...does it go in
environment.rb? database.yml? Set a constant in a lib file?
When you''ve got it in a good location, how do you access it?
Thanks!
Sean
2007 Jun 18
2
weakness of helper?
Hi ,
It comes to me that helper has some weaknesses:
1) It is hard to test . No easy way to write test code for it.
(or Just i didn''t know?)
2) Not easy to reuse it on other controller/view/model.
it looks like to that putting the helper code into a model (a
fully helper model , or a mixed model) is good practice.
However i agree that some html intensive
2006 Jun 02
6
Set instance variable for all actions in the Controller
Can I set an application wide instance variable that is available for all
actions...and their views?
eg.
class ApplicationController < ActionController::Base
@current_user = User.find(session[:user_id])
end
and everywhere I can call @current_user.id and I can get that object? Even
down in the views?
I could not get this to work...
Thanks in advance,
Jeff
-------------- next part
2006 Jan 19
7
validates_numericality_of positive integer
Hi,
What is the simplest way to validate a positive integer?
validates_numericality_of :foo, :integer_only => true
how do I add the positive part? Do I need another validation statement
for pattern matching or do I have to write a validate() funciton for
my model?
Thanks,
Peter
2006 Jul 10
2
cross controller functional tests?
Hi,
I have an online store and I would like to simulate a complete
shopping trip which involves several controllers? How can I write a
test that calls actions from different controllers in a particular
sequence? Something like the following which involves department,
product, cart_item, and cart controllers.
get department 5
check it has a link to product 4
get product 4
post cartitem/create
get
2008 Jun 13
3
before_filter order of execution
Hi
I''m trying to use before_filter to allow access to a site. Only logged
in users can view any object in the controller, but only users with a
access_level higher than 2 can view specific objects. My code is:
-----------------------------------------------------------
IN USER_CONTROLLER
before_filter :login_required
before_filter :access_granted, :only => [:destroy, :new , :edit]
2011 Dec 05
1
How to extend common helper methods to view specs?
Hi, there,
I have some methods which I have written as helpers.
They are in spec/support/controller_macros.rb (yes, I will change the
name soon).
The 2 methods, login_user and login_admin_user works in the
controller specs BUT fail to work in the view specs when I call them
in the view specs.
---------- spec/spec_helper.rb start --------------------------
# This file is copied to spec/