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)...
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.
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.
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
<p> or <br> tags or wrapping your text in <pre> tags. The
simple_format helper will do the former for you.
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
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 ?