Displaying 20 results from an estimated 75 matches for "instance_variable_get".
2006 Mar 20
2
Rails Plugin to Help Debug Views
Hi,
I just released a plugin to help debug views. The plugin makes it easy
to add a button that will popup a new window that displays the
following debug data;
* Request Parameters
* Session Variables
* Flash Variables
* Assigned Template Variables
It was derived from code that traces back to Marten Veldthuis in
Epilog. You can check out webpage and plugin via;
2009 Oct 14
2
How to configure every (postgresql) db connection?
I would like to set some db session variables specific to my
application on the database connection that rails uses. They can be
set by issuing an SQL command like "SET statement_timeout = 1000"
once - it will be in effect for every subsequent SQL statement that
uses this connection.
So I tried to put the following into an initializer:
ActiveRecord::Base.connection.execute("SET
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and
automatically populate, but it shouldn''t be based on AR. In fact I
often have a bunch of small forms that I can''t really justify writing
a whole new model class for anyway. I''d like to validate the form
input, and then use rails helpers to automatically populate the form
if validations fail.
2008 May 01
5
Changing text in view with variables
in my view:
<% if @main_singer_1 == @your_singer %>
<% if @main_drummer_1 == @your_drummer %>
i want to have this in a loop so i can change _1
How would I do this.
I have some idea but I am not sure.
[1..20].each do .....
and then replace _1 with each of the numbers
or if someone can show the code to do this.
number = "1"
<% if
2006 Jan 17
2
file_column plugin and instance variables
..._for_file_column(''product'', ''image_url'') %></p>
This is needed because file_column specifically looks for the instance
version of the variable.
def url_for_file_column(object, method, subdir=nil)
case object
when String, Symbol
object = instance_variable_get("@#{object.to_s}")
end
Is this normal or is there some way to fix this in file_column?
--
Jon Smirl
jonsmirl@gmail.com
2007 Mar 18
7
How to get more informations about an association at runtime
Hi all
I''m working on a Custom Formbuilder. I want it to create me with a
single method call checkboxes for a given HABTM association.
My model looks like this:
[code=ruby]class Member < ActiveRecord::Base
has_and_belongs_to_many :preferred_music_styles,
:class_name => ''MusicStyle'',
:join_table =>
2005 Mar 09
9
Unit testing + instance variables
...response = ActionController::TestResponse.new
create_fixtures "recipes"
create_fixtures "categories"
end
def test_list
get :list
# This step seems exessively complex, and took me a while to figure out
my_inst_vars = @controller.instance_variable_get "@assigns"
assert_equal( 5, my_inst_vars["recipes"].size )
assert_equal( 8, my_inst_vars["categories"].size )
end
end
2008 Jan 16
1
session data and user stories
...e(__FILE__)
require ''rubygems''
require ''spec/story''
require "#{dir}/helper"
steps_for(:dealer_login) do
Given("I have opened a session") do
@session = open_session
end
Given("I am not logged in") do
@session.instance_variable_get("@session").should == nil
end
Given("I have a valid login/password combo") do
@login_with = valid_dealer_credentials
end
When("I submit my login/ password") do
@session.post("/gateway", :user=> @login_with)
end
#there has...
2010 Aug 18
2
RSpec 2/Rails 3 - content_for in view specs
My main layout includes separate content_for/yield sections for my header,
sidebar, footer, and content. However, when running a view spec, the
`rendered` variable seems to only contain a string of just the primary
content and ignores the header/footer/sidebar as well as the rest of my
layout file (the "render" call just returns my primary content wrapped in
generic <html> and
2006 Oct 05
3
Exception Notifier plugin has stopped working.
...ong number of arguments (1 for 0)) on line
#3 of
vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml:
1: <% for variable in @request.session.instance_variables -%>
2: <% next if variable =~ /^@db/ -%>
3: * <%= variable %>: <%=
PP.pp(@request.session.instance_variable_get(variable),"").gsub(/\n/,
"\n ").strip %>
4: <% end -%>
/usr/local/lib/ruby/1.8/pp.rb:244:in `method''
/usr/local/lib/ruby/1.8/pp.rb:244:in `pretty_print''
/usr/local/lib/ruby/1.8/pp.rb:126:in `pp''
...snipped...
---
--
Poste...
2012 Sep 14
1
calling method on base intended to simulate initialize on instances?
class A
def initialize
setup_b
setup_c
end
def b_and_c
"#{@b} and #{@c}"
end
private
def setup_b
@b = ''b''
end
def setup_c
@c = ''c''
end
def setup_d
@d = ''d''
end
end
a = A.new
a.instance_variable_get("@b") # => "b"
a.instance_variable_get("@c") # => "c"
a.instance_variable_get("@d") # => nil
a = A.new.b_and_c # => "b and c"
Now what I did above is to make a point. initialize allows us to
create some initial setup for new...
2006 Jan 17
5
simple question
How do I pass parameters from one controller to another during
redirect_to command? I want to pass both model and non-model objects.
The solution I use is via session, but I rather pass it as parameters to
the redirect_to
Thanks.
--
Posted via http://www.ruby-forum.com/.
2006 Jan 29
6
tyro Ruby questin
Trying to print out a simple database grid, using, with column headers
such as ''SunToSatRoles'', ''PrimaryRoles'', etcetera.
Iterating through an object @List which is populated thusly
@list = mymodel.find(:all, :order => mymodel.editlist_order)
When I do something like
<table>
<% for i in @list %>
<tr>
<td><%= i.inspect
2006 Feb 01
4
Custom view helpers
Hi all,
I would like to write some custom helpers like the ones available as
form helpers text_field, text_area and the like. My first try was this:
custom_helper(obj, meth)
''some_string'' + obj.send(meth) + ''some_other_string''
end
Object and method are being passed as symbols like this:
custom_helper(:person, :name)
and Ruby rightfully complains that
2005 Dec 22
2
Accessing an instance variable by its name (as a string)
Hi (again!)
I have a function which gets passed the name of an instance variable,
and spits its out all nicely formatted.
Just wondering, how do i access the variable, when all i have is its
name stored as a string?
So far i''ve got this code, but it looks horrible. Is there a better way?
eval("@" << inst_var_name << "." << field_name <<
2007 Aug 18
1
problem with file_column url generator
...I have the following in a viewer
Here, @lst = Homework.find(:all) is an array of homeworks. I checked
this this is correct.
Based on the error below, somehow, the url_for_file_colum does not
like to act on the model element.
I checked the source code to url_for_file_column, and the problem is
with instance_variable_get().
I have no idea wat is going on! Any help is appreciated. Gordon.
----------------
<% @lst.each do |hwk| %>
<p>
<%= link_to File.basename(hwk.file_name), url_for_file_column(hwk,
"file_name") %>
</p>
<% end %>
---------------------
The File.bas...
2007 Jan 03
2
error_message_on broken?
Hi,
in my app, using the error_message_on form helper like this:
<label for="user_name">User name:</label>
<%= error_message_on ''user'', :name %>
<%= f.text_field :name %>
generates the following error:
undefined method `errors'' for :user:Symbol
I am using edge revision 5813 and the simply_helpful plugin. Is there a
way to fix this?
2007 Apr 04
2
unit tests?
Ezra et al:
I have this problem:
http://rubyforge.org/pipermail/backgroundrb-devel/2006-December/000578.html
Any progress on it? Or are unit tests simply impossible for now?
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!
2005 Dec 23
1
Overloading error_message_on method in ActiveRecordHelper
...ire ''action_view/helpers/active_record_helper''
module ActionView
module Helpers
module ActiveRecordHelper
def error_message_on(object, method, prepend_text = "",
append_text = "", css_class = "formError", span = false)
if errors = instance_variable_get("@#{object}").errors.on(method)
content_tag(span ? "span" : "div",
"#{prepend_text}#{errors.is_a?(Array) ? errors.first :
errors}#{append_text}", :class => css_class)
end
end
end
end
end
---
My plan is to be able to use this...
2005 Dec 27
0
Re: RESOLVED: Overloading error_message_on method in ActiveRecordHelper
...class == Hash
prepend_text = params[:prepend_text] || ""
append_text = params[:append_text] || ""
css_class = params[:css_class] || "formError"
span = params[:span] || false
end
if errors = instance_variable_get("@#{object}").errors.on(method)
content_tag(span ? "span" : "div",
"#{prepend_text}#{errors.is_a?(Array) ? errors.first :
errors}#{append_text}", :class => css_class)
end
end
end
end
end
---
I don''t know if this is t...