Attach an action to a partial?

Is it possible to render a partial with an action attached to it, just
like the regular views? Or should I just call the action which renders
the partial?

Aldric G. wrote:

Is it possible to render a partial with an action attached to it, just
like the regular views? Or should I just call the action which renders
the partial?

Uh…what? How does any view, partial or not, have an action attached?
What in the world do you mean?

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

Aldric G. wrote:

Is it possible to render a partial with an action attached to it, just
like the regular views? Or should I just call the action which renders
the partial?

Uh…what? How does any view, partial or not, have an action attached?
What in the world do you mean?

http://localhost:3000/Users/index

That’s a view, right?
In the controller, there’s “def index […] end”, right? That’s an
action, right?

So when you go to “index”, Rails calls the Ruby method “index” in the
appropriate controller, doesn’t it?

Aldric G. wrote:

Marnen Laibow-Koser wrote:

Aldric G. wrote:

Is it possible to render a partial with an action attached to it, just
like the regular views? Or should I just call the action which renders
the partial?

Uh…what? How does any view, partial or not, have an action attached?
What in the world do you mean?

http://localhost:3000/Users/index

That’s a view, right?

No. That’s a URL. The view would be app/views/users/index.html.haml or
some such.

In the controller, there’s “def index […] end”, right? That’s an
action, right?

Right.

So when you go to “index”, Rails calls the Ruby method “index” in the
appropriate controller, doesn’t it?

Assuming standard routing, yes.

This does not make your original question any more comprehensible. :slight_smile:

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

James E. wrote:

Like a tile controller from the java world I would suppose.

Essentially a block of code in an .rb file that gets executed every time
the
partial is rendered.

I don’t think you can do that? Can you?

Of course you can. What do you think a helper is? Or a component?

On Fri, Jan 15, 2010 at 9:00 AM, Marnen Laibow-Koser

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Like a tile controller from the java world I would suppose.

Essentially a block of code in an .rb file that gets executed every time
the
partial is rendered.

I don’t think you can do that? Can you?

On Fri, Jan 15, 2010 at 9:00 AM, Marnen Laibow-Koser

2010/1/15 Aldric G. [email protected]:

http://localhost:3000/Users/index

That’s a view, right?

No, it is a URL

In the controller, there’s “def index […] end”, right? That’s an
action, right?

So when you go to “index”, Rails calls the Ruby method “index” in the
appropriate controller, doesn’t it?

You have it the wrong way round, clicking on the URI causes the index
action to be performed, then that causes a view to be rendered.

Colin

Well yes… That’s not really quite the same though…

On Fri, Jan 15, 2010 at 9:14 AM, Marnen Laibow-Koser

[Please quote when replying. This is a mailing list, not just a Web
forum.]

James E. wrote:

Well yes… That’s not really quite the same though…

On Fri, Jan 15, 2010 at 9:14 AM, Marnen Laibow-Koser

Where do you see the difference? You were asking about a block of Ruby
code that is executed each time the view is rendered. That is exactly
what a helper is.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

you can render a partial in your action, or you can render your actions
view
and render a partial in it.

http://api.rubyonrails.org/classes/ActionController/Base.html#M000658What
can you tell me about the Tile thing?

Maybe I’m misunderstanding you. Your talking about putting a helper in
a
view, right?

So

<%= my_helper %>

would be the code?

On Fri, Jan 15, 2010 at 9:25 AM, Marnen Laibow-Koser

James E. wrote:

Maybe I’m misunderstanding you. Your talking about putting a helper in
a
view, right?

So

<%= my_helper %>

would be the code?

Well, it would call FooHelper#my_helper, which would contain the code.

On Fri, Jan 15, 2010 at 9:25 AM, Marnen Laibow-Koser

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

Aldric G. wrote:

Marnen Laibow-Koser wrote:

So when you go to “index”, Rails calls the Ruby method “index” in the
appropriate controller, doesn’t it?

Assuming standard routing, yes.

This does not make your original question any more comprehensible. :slight_smile:

When I go to the URI : http://localhost:3000/Ultrasounds/index
I query a database for a list of ultrasounds and display that list under
a button called “Fix ultrasounds”.
When I click that button, I want it to run the attached method, which it
does, and I want that list to be re-queried and re-displayed.

So, should I:

  1. have this list displayed in a partial
  2. the view set up with a div
  3. in the “index” method, call the method which does the query, then
    renders the partial in that div
  4. when the button is clicked, re-call the method which does the query
    and renders the partial in that div

?

Yeah. I got you. I guess the difference is really pretty trivial.

With a “partial controller”, you would define your code like this (made
up
code incoming):

<%= render_partial ‘some_partial’, :controller => ‘SomeClass’ %>

Rails would then call a method on SomeClass before it renders the
partial.
This would allow you to put some logic in SomeClass without adding any
code
to the view itself.

The difference is simply semantic and not that important… Just trying
to
offer some understanding to the original question =]

On Fri, Jan 15, 2010 at 9:48 AM, Marnen Laibow-Koser