# Parameters

**URL:** <https://www.ruby-forum.com/t/parameters/144785>\
**Category:** Rails\
**Created:** [August 2, 2008, 1:06am UTC](https://www.ruby-forum.com/t/parameters/144785 "2008-08-02T01:06:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 2, 2008, 1:06am UTC](https://www.ruby-forum.com/t/parameters/144785/1 "2008-08-02T01:06:36Z")

</div>

\<% for post in @posts %\>

\<%= link\_to\_remote “Edit”, :url =\> { :controller =\> “threads”, :action  
=\> :new\_req }, :with =\> “‘description=#{post.description}’”

\<% end %\>

When I make a post with the form and enter a description like such:

Description text\_area:  
this is a description  
that has linebreaks,  
or… at least,  
I have pressed enter  
several times.

It can save fine when made with the form. But in my first code, when I  
try to set params[:description] = post.description, it doesn’t work  
properly. Not sure why. It only happens when I make a description and  
hit enter one or more times (have linebreaks)…

Any help is much appreciated!

Thanks

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 2, 2008, 1:23am UTC](https://www.ruby-forum.com/t/parameters/144785/2 "2008-08-02T01:23:05Z")

</div>

On 2 Aug 2008, at 00:06, Justin To wrote:

> \<% for post in @posts %\>
> 
> \<%= link\_to\_remote “Edit”, :url =\> { :controller =\>  
> “threads”, :action  
> =\> :new\_req }, :with =\> “‘description=#{post.description}’”
> 
> \<% end %\>

You don’t need to use :with for this. But apart from that, the problem  
is that you’re not escaping the description. The post I linked you to  
the other day about the usage of the :with parameter covered both of  
these things.

Fred

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 3, 2008, 1:05am UTC](https://www.ruby-forum.com/t/parameters/144785/3 "2008-08-03T01:05:10Z")

</div>

Frederick C. wrote:

> On 2 Aug 2008, at 00:06, Justin To wrote:
> 
> > \<% for post in @posts %\>
> > 
> > \<%= link\_to\_remote “Edit”, :url =\> { :controller =\>  
> > “threads”, :action  
> > =\> :new\_req }, :with =\> “‘description=#{post.description}’”
> > 
> > \<% end %\>
> 
> You don’t need to use :with for this. But apart from that, the problem  
> is that you’re not escaping the description. The post I linked you to  
> the other day about the usage of the :with parameter covered both of  
> these things.
> 
> Fred

The encodeURIComponent doesn’t seem to make a difference.

Mmm… a user fills out the textarea with a form\_for (for a model  
object). When I do \<% for post in @posts %\> \<%= post.description %\> It  
doesn’t show the linebreaks that I entered. So if I enter (into the  
textarea):  
dsfksdf (enter)  
sdfsdf (enter)  
sfdsdf

I guess it doesn’t save it in the first place because with \<%=  
post.description %\> I get dskfsdf sdfsdf sfdsdf. But I can’t even send  
that as a parameter to populate a form.

Any suggestions would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 3, 2008, 1:10am UTC](https://www.ruby-forum.com/t/parameters/144785/4 "2008-08-03T01:10:20Z")

</div>

> Mmm… a user fills out the textarea with a form\_for (for a model  
> object). When I do \<% for post in @posts %\> \<%= post.description %\> It  
> doesn’t show the linebreaks that I entered. So if I enter (into the  
> textarea):  
> dsfksdf (enter)  
> sdfsdf (enter)  
> sfdsdf
> 
> I guess it doesn’t save it in the first place because with \<%=  
> post.description %\> I get dskfsdf sdfsdf sfdsdf.

Ah, I misunderstood what wasn’t working. HTML ignores linebreaks so  
what you’re seeing is normal. you either need to be inserting your own

or   
 tags or wrapping your text in

```
tags. The
simple_format helper will do the former for you.

Fred
```

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 4, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/parameters/144785/5 "2008-08-04T18:42:59Z")

</div>

Hey Fred, I’m still having some problems =\

In my first post:  
\<% for post in @posts %\>

\<%= link\_to\_remote “Edit”, :url =\> { :controller =\> “threads”, :action  
=\> :new\_req }, :with =\> “‘description=#{post.description}’”

\<% end %\>

1. You said I didn’t need to use :with. How would I access the  
post.description otherwise?
2. I used the simple\_format helper, so it displays correctly now, but
3. Still having trouble calling my ‘new\_requirement’ action to edit,  
with:  
view:  
\<% for post in @posts %\>  
\<%= link\_to\_remote “Edit”, :url =\> { :controller =\> “threads”,  
:action =\> :new\_req }, :with=\>"‘req\_id=#{post.requirement\_id}’ + ‘&’ +  
‘title=#{post.title}’ + ‘&’ + ‘description=’ +  
‘#{simple\_format(post.description)}’ + ‘&’ +  
‘justification=#{post.justification}’ + ‘&’ + ‘tags=#{post.tags}’",  
:class=\>“edit” %\>  
\<% end %\>

controller:  
def new\_requirement  
@post = Post.new

```
respond_to do |format|
      format.html { redirect_to_index}
      format.js
    end

```

end

rjs  
page.replace\_html :control, :partial =\> ‘new\_req’  
page[:control].visual\_effect :slide\_down

partial:  
\<% form\_for :post, :url =\> { :action =\> :save\_requirement } do |form| %\>  
\<%= form.text\_area :description, :value =\> params[:description], :class  
=\> “textarea” %\>  
\<% end %\>

Thanks for helping me out!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 4, 2008, 6:50pm UTC](https://www.ruby-forum.com/t/parameters/144785/6 "2008-08-04T18:50:08Z")

</div>

On 4 Aug 2008, at 17:42, Justin To wrote:

> \<% end %\>
> 
> 1. You said I didn’t need to use :with. How would I access the  
> post.description otherwise?  
> stick it in the :url hash.
> 
> 2. I used the simple\_format helper, so it displays correctly now, but
> 
> 3. Still having trouble calling my ‘new\_requirement’ action to edit,  
> with:

I’m not entirely sure what you’re doing here. You’re passing a bunch  
of parameters to this action but then you’re not using any of them.  
And why pass all those parameters when you could just as easily pass  
the post id ?

Fred

> controller:  
> def new\_requirement  
> @post = Post.new

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 4, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/parameters/144785/7 "2008-08-04T20:21:01Z")

</div>

is there any way to simulate, like in Ruby,

p post.description

so i can see all the goodies?

Thanks

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 4, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/parameters/144785/8 "2008-08-04T20:28:45Z")

</div>

Never mind. Finally, I figured it out. I think passing the post\_id  
instead of all the params made the difference.

Thanks for all the continued help Fred!!!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 4, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/parameters/144785/9 "2008-08-04T20:17:40Z")

</div>

Alright, I passed the post\_id instead:

\<%= link\_to\_remote “Edit”, :url =\> { :controller =\> “threads”, :action  
=\> :new\_req }, :with=\>"‘post\_id=#{post.id}’" %\>

I’m using the params[:post\_id] in the view that the action :new\_req is  
displaying, to populate my form fields.

\<% post = Post.find\_by\_id params[:post\_id] if params[:post\_id] %\>  
…  
Title:\<%= form.text\_field :title, :value =\> “”||post.title, :id=\>“title”  
%\>  
…

Thanks again
