I have a module @post where user can write their own posts. Problem is that these posts are without paragraphs and users can’t start write in the new line. Maybe there is gems which allows that? I am using Ruby on Rails 3.2.1.
For example this text:
This text is bold,
This text is italic
This is list:
- item 1;
- item 2;
But in my home page this will look like this:
This text is bold This text is italic This is list: 1. item 1; 2. item 2;
I hope you understand what I mean…
@post show:
<div id="content">
<div class="post">
<h1 class="title"><%=@post.title%></h1>
<p class="byline"style="text-align: right; font-weight: bold;">Raksts izveidots: <%= @post.created_at.utc.strftime("%d.%m.%Y") %></p>
<div class="entry">
<p><%= @post.content %></p>
<%= image_tag @post.bildes.url(:medium) %>
<%= image_tag @post.bildes.url(:thumb) %>
</div>
</div>
@post form:
<div id="content">
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<% create_url = {:url=>{:action=>"create"}} if @post.new_record? %>
<% form_for @post, :html => { :multipart => true } do |t| %>
<b><%= t.label :title, 'Virsraksts:' %></b><br />
<%= t.text_field :title %><br /><br />
<b><%= t.label :content, 'Teksts:' %></b><br />
<%= t.text_area :content %><br /><br />
<b><%= t.label :bildes, 'Pievienot bildes:' %></b><br />
<%= f.file_field :bildes %><br /><br />
<%= t.submit %>
<% end %>
<%end%>
Maybe I didn’t get you right. But I think you need to use a rich text editor on the page.
There’s plenty of rich text editor out there, I recommend you to checkout Tinymce, it’s also used by wordpress.
So that the user could input in paragraphs and control other formats, which will result in html format and keep all the styles.
I am using
gem 'tinymce-rails'to integrate Tinymce with rails. It just import the tinymce into the assets pipeline, not providing any helpers but I think it’s quite good, works well with the assets pipeline, that’s enough for me, I don’t like some much wrapping for this, Here is the link: tinymce-rails. You could also find a lot other gems which provide more close integration with rails.