Rails Generate Scaffold only shows a little bit of my post - ruby-on-rails

I generated a scaffold so that i can post blog entries into my site.
I already made one for articles which works the way i wanted...
However i generated another one for reviews but when i post my reviews only a couple of sentences show and not the whole review. When i go back to edit the review most of my review is gone and only a couple of sentences shows up.....
I can't seem to add more than a couple of sentences for some reason.....
It has nothing to do with the CSS since i turned all styles off and i still get the same results
Heres the Show Page
<div class="container">
<div class="row">
<div class="span4">
<%= image_tag #comic_review.photo %>
</div>
<div class="span8 comic_review_content">
<h3>
<b><%= #comic_review.title %></b>
</h3>
<br />
<p>
<b>Synopsis:</b>
<%= #comic_review.content %>
</p>
<p>
<b>Credits:</b>
<%= #comic_review.credits %>
</p>
<h3>Review</h3>
<div class="line_section"></div>
<p><%= simple_format #comic_review.review %></p>
<%= link_to 'Edit', edit_comic_review_path(#comic_review) %> |
<%= link_to 'Back', comic_reviews_path %>
<div class="comment_count">
All Comments (<%= #comic_review.comments.count %>)
</div>
<%= render "comments/comments" %>
<%= render "comments/form" %>
</div>
Heres the actual form
<%= form_for #comic_review, :html => { :multipart => true } do |f| %>
<% if #comic_review.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#comic_review.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% #comic_review.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<b>Title</b>
<br />
<%= f.text_field :title, class: 'form_field1' %>
</div>
<br />
<div class="field">
<b>Author</b>
<br />
<%= f.text_field :credits, class: 'form_field1' %>
</div>
<br />
<div class="field">
<b>Date</b>
<br />
<%= f.text_field :content, class: 'form_field1' %>
</div>
<br />
<%= f.file_field :photo, class: "photo_upload" %>
<br />
<br />
<div class="field">
<b>Content</b>
<br />
<%= f.text_field :review, rows: 25, class: 'form_field' %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
I dont know whats going on any help would be appreciated thank you in advance

In your database, is the type of the review column VARCHAR(255)? If so, that would be because you did review:string when you generated the scaffold; string gets converted to VARCHAR(255), and at least with MySQL, if you insert a string with more than 255 characters into a column of that type, it truncates everything after the first 255 characters.
The fix is to change the column type. Log in to the mysql console unser your database, and run:
ALTER TABLE comic_reviews CHANGE review review TEXT;

Related

Why am I missing an input in a form after scaffolding in Rails?

I'm learning Rails and I try to use scaffold to generate some code.
Everything seems to be OK after this except I miss an input in one of my forms and I don't know why.
Someone could explain this ?
Here the partial form which generates the view:
_form.html.erb
<%= form_with(model: advertisement, local: true) do |form| %>
<% if advertisement.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(advertisement.errors.count, "error") %> prohibited this advertisement from being saved:</h2>
<ul>
<% advertisement.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :content %>
<%= form.text_area :content %>
</div>
<div class="field">
<%= form.label :price %>
<%= form.number_field :price %>
</div>
<div class="field">
<%= form.label :state %>
<%= form.text_field :state %>
</div>
<div class="field">
<%= form.label :user_id %>
<%= form.number_field :user_id %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
The HTML output for this input:
<div class="field">
<label for="advertisement_title">Title</label>
<input type="text" name="advertisement[title]" id="advertisement_title" />
</div>
Thank you everyone
OK I got it!
It's because of the Adblock extension.
On every page where it is enabled, it injects CSS directly into the page and adds a
display: none !important;
for hundreds of defined id's.
Unfortunately for me, #advertisement_title is one of them!
It works when I desactivate it
adblock display none

Raty star rating not showing up

So I'm following a tutorial and near 1:07:39 in the New Review page, he has rating field and a comment field. But for me, only the comment page shows up, and I've tried copying his movie controller, reviews controller and the _form.html.erb. I am using ruby on rails and using the cloud 9 editor. All help is appreciated. If there's anything I have to add please comment.
This is my form:
<%= form_for([#movie, #review]) do |f| %>
<% if #review.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#review.errors.count, "error") %> prohibited this review from being saved:</h2>
<ul>
<% #review.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<div id="star-rating"></div>
</div>
<div class="field">
<%= f.label :comment %><br>
<%= f.text_area :comment %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<script>
$('#star-rating').raty({
path: '/assets/',
scoreName: 'review[rating]'
});
</script>
Your div for the rating is (probably) missing the label and text_field. You should do something like this:
<div class="field">
<div id="star-rating"></div>
<%= f.label :rating %><br>
<%= f.text_field :rating %>
</div>

How to link title of resource?

This is what Things look like on my site.
I want "Cole Haan Air Madison" to actually link to the Cool Haan website where users can purchase that item.
This is the code for the form used to create Things:
<%= simple_form_for(#thing, html: { multipart: true }) do |f| %>
<% if #thing.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#thing.errors.count, "error") %> prohibited this thing from being saved:</h2>
<ul>
<% #thing.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :title %><br>
<%= f.text_field :title, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :description %><br>
<%= f.text_field :description, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :image %><br>
<%= f.file_field :image, class: 'form-control' %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
The form visually looks like this:
I know I have to add a link field to the form. But how do I, instead of displaying the link to the user, have it correspond to the title of the Thing?
Here is the show view for Things:
<div class='row'>
<div class='col-md-offset-2 col-md-8'>
<div class='panel panel-default'>
<div class='panel-heading text-center'>
<%= image_tag #thing.image.url(:medium) %>
</div>
<div class='panel-body'>
<p>
<strong><%= #thing.title %></strong>
</p>
<p>
<%= #thing.description %>
</p>
<p>
<%= link_to #thing.user.username, #thing.user %>
</p>
<% if #thing.user == current_user %>
<%= link_to edit_thing_path(#thing) do %>
<span class='glyphicon glyphicon-edit'></span>
<% end %>
<% end %>
</div>
</div>
</div>
Basically, you need link_to tag.
Since, you mentioned:
I want "Cole Haan Air Madison" to actually link to the Cool Haan
website where users can purchase that item.
So, I consider that you are storing website of the user's thing.
Replace,
<strong><%= #thing.title %></strong>
in your code with:
<strong><%= link_to #thing.title, #thing.user.website %></strong>
Here, #thing.user denotes the associated user of that thing, and #thing.user.website gives back the website of that user.

Submitting a form doesn't work after time, only after refreshing

I have a Simple Form and i just realized that if edit the form long enough (5-10secs) the Submit button suddenly doesn't work.
If i refresh the page and quickly type some letters and the submit it, it works...
This behavior is active on everything in my app that has a scaffold form, for example my Devise form's are just fine.
I have no idea what is causing this behavior.. What am i missing ?
EDIT
This behavior occurs only in Google Chrome Browsers.
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h1>Test Form</h1>
</div>
</div>
<div class="panel-body">
<%= form_for(#question) do |f| %>
<% if #question.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#question.errors.count, "error") %> prohibited this question from being saved:</h2>
<ul>
<% #question.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :title %><br>
<%= f.text_field :title, class: "form-control", :autofocus => true,
placeholder: "#"%>
</div>
<div class="form-group">
<%= f.label :body %><br>
<%= f.text_area :body, class: "redactor redactor-box" %>
</div>
</div>
<div class="panel-footer">
<div class="form-group">
<%= f.submit "Post", class: "btn btn-primary" %>
</div>
</div>
<% end %>
</div>
It seems that the problem was in the HTML.
I wrapped all my html tags with form_for and for now it seems to be working..

Update record error when combined with delete

I have a problem at the moment with my _form.html.erb for editing a game. My code for this class is as followed:
<%= form_for #game, :html => { :multipart => true } do |f| %>
<% if #game.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#game.errors.count, "error") %> prohibited this game from being saved:</h2>
<ul>
<% #game.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<div id="p1"><%= f.label :game_name %> </div>
<%= f.text_field :game_name %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :genre %> </div>
<%= f.text_field :genre %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :console %> </div>
<%= f.select :console, Game::CONSOLE_OPTIONS, :prompt => 'Select' %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :condition %> </div>
<%= f.text_field :condition %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :description %> </div>
<%= f.text_area :description, :rows => 6 %>
</div>
<%= f.file_field :photo %>
<br />
<div class="actions">
<%= f.submit %>
<%= button_to 'Destroy', root_url, :confirm => 'Are You Sure?', :method => :delete %>
</div>
<% end %>
The problem I have is as followed. If I click the delete button it will delete the record no problem, but if I click the update button it removes the record also. If I take out the delete command then it updates fine. How can I get both to display together whilst doing their individual duties?
You need extract your destroy button from your form_for of update.

Resources