Locals in partials

hiya, in specing a partial, how can i assign a local var that is
normally passed via :locals ? i tried adding :locals => to the render
call but that doesnt seem to take

linoj

Hi Jon,

I was having trouble with partials a while ago and I think it might have
info on solving your problem

http://www.nabble.com/spec'ing-view-render-partial-collection%2C-local-variable-not-found-tf4577761.html

I’m guessing your referring to when you called your parital in a spec:

it “should show game name” do
render :partial =>“games/game”, :locals => {:game => @game}
response.should have_tag(‘h3’, /The Battle for Blaze/)
end

You need to provide a bit more information about your specs such as code
and
reported error.

On 10/12/07, Jonathan L. [email protected] wrote:

[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


Monsterbox Productions
putting small businesses on-line

1319 Victoria Avenue East
Thunder Bay, Ontario P7C 1C3
Canada

Andrew WC Brown
web-developer and owner
[email protected]
P: 807-626-9009
F: 807-624-2705

On Fri, 2007-10-12 at 10:33 -0400, Jonathan L. wrote:

hiya, in specing a partial, how can i assign a local var that is
normally passed via :locals ? i tried adding :locals => to the render
call but that doesnt seem to take

it ‘should include :var’
render :partial => ‘your/partial’, :locals => {:var => ‘value’}
response.should …
end

Something like that should work. Otherwise, please post your code,
that’ll make it a lot easier to help out.

Kind regards,

Hans

that works for you?
I’m basically doing the same thing but the

render “/pages/_page_menu.html.erb”, :locals => { :pages => @foo }

produces error

undefined local variable or method `pages’ for #<ActionView::Base:
0x33a1f6c>

but it works when i add to the top of the partial:

<%# pages ||= @foo #kludge for rspec %>

oops, of course that last line wouldnt be commented out

On 10/12/07, Hans de Graaff [email protected] wrote:

On Fri, 2007-10-12 at 12:47 -0400, Jonathan L. wrote:

that works for you?
I’m basically doing the same thing but the

render “/pages/_page_menu.html.erb”, :locals => { :pages => @foo }

render :partial => ‘pages/page_menu’, :locals => {:pages => @foo}

Note the :partial.

Yes - that’s correct. The render method in view specs delegates to
rails’ render method, but allows you to skip the :template key in the
hash as a convenience:

render ‘/path/to/template’

If you don’t specify what ‘/path/to/template’ represents, it is passed
like this:

controller.render :template => ‘/path/to/template’

So if you add additional pairs to the hash, they just get passed to
AC::Base, which only deals with :locals, :object and :collection if
you specify that you’re using a partial.

Cheers,
David

On Fri, 2007-10-12 at 12:47 -0400, Jonathan L. wrote:

that works for you?
I’m basically doing the same thing but the

render “/pages/_page_menu.html.erb”, :locals => { :pages => @foo }

render :partial => ‘pages/page_menu’, :locals => {:pages => @foo}

Note the :partial.

Kind regards,

Hans

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs