使用submit_to_remote提交的Rails控制器中的textarea預先設置換行符 - Preseve line breaks from textarea in Rails controller submitted with submit_to_

使用submit_to_remote提交的Rails控制器中的textarea預先設置換行符 - Preseve line breaks from textarea in Rails controller submitted with submit_to_,第1张

I can't believe there isn't a standard way of doing this, but I'm submitting content from a textarea to a Rails controller, and it doesn't seem to preserve the line breaks (of any form).

我無法相信沒有一種標准的方法可以做到這一點,但是我將內容從textarea提交給Rails控制器,它似乎沒有保留換行符(任何形式)。

Here is my view code:

這是我的觀看代碼:

f.text_area :keywords, :cols => 50, :rows => 10

submit_to_remote 'button',  "#{t "add_keywords"}", 
     :html => {:id => 'add_keywords_button'},
     :url => { :controller=> :keywords, :action => :add_to_site },
     :escape => true,
     :loading=>"Form.Element.disable('add_keyword_button')",
     :complete=>"Form.Element.enable('add_keyword_button');",
     :update => { :success => "keywords_table_decorator", :failure => "message"

After submitting this goes to a controller that just needs to be able to parse out each keyword, line by line. I've tried all of the variations on the following theme:

提交后,這將轉移到一個控制器,只需要能夠逐行解析每個關鍵字。我已經嘗試了以下主題的所有變體:

@keywords = params[:site_keywords][:keywords]
puts @keywords.gsub(/\n|\r|\r\n/,'*')

just to see if I can get something that I can do a further split with.

只是為了看看我是否可以得到一些我可以進一步拆分的東西。

I'd appreciate advice on getting this to work.

我很欣賞讓這個工作起來的建議。

1 个解决方案

#1


2  

Figured it out. I had this in my reset.css for all textareas:

弄清楚了。所有textareas都在我的reset.css中有這個:

white-space: normal; 

Removing it made the problem go away.

刪除它使問題消失。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复