# Render a partial file

**URL:** <https://www.ruby-forum.com/t/render-a-partial-file/132143>\
**Category:** Rails\
**Created:** [March 17, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143 "2008-03-17T12:15:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/1 "2008-03-17T12:15:26Z")

</div>

Hi all…  
Can we render a partial file while clicking on a link?

I tried the following:

\<%= link\_to\_remote( “Cancel”,  
:update =\> “edit\_func\_spec\_div”,  
:url =\> {:partial =\>  
‘cipart/show\_functional\_spec\_to\_edit’}  
) %\>

But it didn’t rendered the partial file specified.

Also i need to pass a variable to this partial file. How can i do this?

Please help

Thanks in advance  
Regards  
Suneeta

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/2 "2008-03-17T12:18:35Z")

</div>

On 17 Mar 2008, at 11:15, Suneeta Km wrote:

> ```
> ) %>
> 
> ```

You can do this, but not like that. The action you specify by the :url  
hash can render any partial you fancy.

Fred

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/3 "2008-03-17T12:28:17Z")

</div>

Frederick C. wrote:

> On 17 Mar 2008, at 11:15, Suneeta Km wrote:
> 
> > ```
> > ) %>
> > 
> > ```
> 
> You can do this, but not like that. The action you specify by the :url  
> hash can render any partial you fancy.
> 
> Fred

Hi Fred…  
Thanks for your reply

I changed my code like this:  
\<%= link\_to\_remote( “Cancel”,  
:update =\> “edit\_func\_spec\_div”,  
:url =\> ‘cipart/show\_functional\_spec\_to\_edit’  
) %\>

But ‘no action found’ message generated.  
cipart is not an action. It is a folder that contains all partial files  
in my project.

So I changed the code as follows:  
\<%= link\_to\_remote( “Cancel”,  
:update =\> “edit\_func\_spec\_div”,  
:url =\> ‘/cipart/show\_functional\_spec\_to\_edit’  
) %\>

Then routing error generated.

Please help to solve this.

Thanks  
Suneeta

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 12:31pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/4 "2008-03-17T12:31:10Z")

</div>

Suneeta Km wrote:

> Hi all…  
> Can we render a partial file while clicking on a link?  
> I tried the following:  
> \<%= link\_to\_remote( “Cancel”,  
> :update =\> “edit\_func\_spec\_div”,  
> :url =\> {:partial =\>  
> ‘cipart/show\_functional\_spec\_to\_edit’}  
> ) %\>

\<%= link\_to\_remote( “Cancel”,  
:update =\> “edit\_func\_spec\_div”,  
:url =\> {:controller =\> ‘mycontroller’, :action =\>  
‘myaction’, :myvar =\> 100 }) %\>

and then, in

Class MyController \< …  
…

def myaction  
myvar = params[:myvar]  
render :partial =\> ‘your/partial’, :locals =\> {:myvar =\> myvar }  
end

end

hth

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 12:43pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/5 "2008-03-17T12:43:29Z")

</div>

Shai R. wrote:

> Suneeta Km wrote:
> 
> > Hi all…  
> > Can we render a partial file while clicking on a link?  
> > I tried the following:  
> > \<%= link\_to\_remote( “Cancel”,  
> > :update =\> “edit\_func\_spec\_div”,  
> > :url =\> {:partial =\>  
> > ‘cipart/show\_functional\_spec\_to\_edit’}  
> > ) %\>
> 
> \<%= link\_to\_remote( “Cancel”,  
> :update =\> “edit\_func\_spec\_div”,  
> :url =\> {:controller =\> ‘mycontroller’, :action =\>  
> ‘myaction’, :myvar =\> 100 }) %\>
> 
> and then, in
> 
> Class MyController \< …  
> …
> 
> def myaction  
> myvar = params[:myvar]  
> render :partial =\> ‘your/partial’, :locals =\> {:myvar =\> myvar }  
> end
> 
> end
> 
> hth

Hi…

Can’t we directly render a partial file in link\_to\_remote?

Thanks  
Suneeta

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/6 "2008-03-17T13:01:15Z")

</div>

On 17 Mar 2008, at 11:43, Suneeta Km wrote:

> Hi…
> 
> Can’t we directly render a partial file in link\_to\_remote?

No you can’t. link\_to\_remote generates javascript to make a request to  
your server. if you want that to render a partial then you need to  
have an action on the other side that renders that partial.

Fred

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/7 "2008-03-17T13:16:10Z")

</div>

Hi…  
Is there any options other than link\_to\_remote for solving my problem?  
Suneeta

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/8 "2008-03-17T21:19:20Z")

</div>

if you didn’t want to use ajax, you could use javascript directly? You  
could render the form on the page, hide it, then show it when you  
click on your link. e.g:

 \<%= render :partial =\> "/cipart/show\_functional\_spec\_to\_edit" %\>

\<%= link\_to\_function “Cancel”, “$(‘my-hidden-form’).show()” %\>

However that depends on how complex your hidden section will be… it  
might not be appropriate.

On Mar 18, 1:16 am, Suneeta Km [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![suneeta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@suneeta](https://www.ruby-forum.com/u/suneeta)\
**Post date:** [March 17, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/render-a-partial-file/132143/9 "2008-03-17T13:13:35Z")

</div>

Frederick C. wrote:

> On 17 Mar 2008, at 11:43, Suneeta Km wrote:
> 
> > Hi…
> > 
> > Can’t we directly render a partial file in link\_to\_remote?
> 
> No you can’t. link\_to\_remote generates javascript to make a request to  
> your server. if you want that to render a partial then you need to  
> have an action on the other side that renders that partial.
> 
> Fred

Thanks Fred.  
I have to implement this function in many places. I was trying to avoid  
writing many actions for such a simple functionality.  
So now i’m planning to write a single action and combine all by checking  
conditions.  
Thanks again  
Suneeta
