Rails 6: Two actioncable channels for real time messaging, one doesnt refresh properly - html

I have two Actioncable channels setup(chatroom_channel and comment_channel). Comment channel isnt working.
The comment is being created and when I manually refresh the page the comment renders. However, the comment is supposed to render without manually pressing the refresh button from the browser.
This is the console output from the one that is working:
Started POST "/messages" for 127.0.0.1 at 2020-07-15 12:54:31 -0400
Processing by MessagesController#create as JS
Parameters: {"message"=>{"content"=>"hello"}, "commit"=>"Send"}
Chef Load (0.1ms) SELECT "chefs".* FROM "chefs" WHERE "chefs"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:11:in `current_chef'
(0.1ms) begin transaction
↳ app/controllers/messages_controller.rb:7:in `create'
Message Create (0.3ms) INSERT INTO "messages" ("content", "chef_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["content", "hello"], ["chef_id", 1], ["created_at", "2020-07-15 16:54:31.377225"], ["updated_at", "2020-07-15 16:54:31.377225"]]
↳ app/controllers/messages_controller.rb:7:in `create'
(62.6ms) commit transaction
↳ app/controllers/messages_controller.rb:7:in `create'
Rendered messages/_message.html.erb (Duration: 0.7ms | Allocations: 247)
[ActionCable] Broadcasting to chatroom: {:message=>"<div class=\"message\">\n <p>\n <small><em>Created less than a minute ago</em></small>\n </p>\n <p>\n <img alt=\"john\" class=\"rounded-circle\" src=\"https://secure.gravatar.com/avatar/1c9e974c08914cda5ca2e7620c4fd3b6?s=50\" />\n <strong>John </strong>\n <span class=\"content\">\n hello\n </span>\n </p>\n</div>", :chef=>"john"}
Completed 200 OK in 82ms (Views: 13.3ms | ActiveRecord: 63.1ms | Allocations: 5133)
ChatroomChannel transmitting {"message"=>"<div class=\"message\">\n <p>\n <small><em>Created less than a minute ago</em></small>\n </p>\n <p>\n <img alt=\"john\" class=\"rounded-circle\" src=\"https://secure.gravatar.com/avatar/1c9e974c08914cda5ca2e7620c4fd3b6?s=50\" />\n <strong>John </strong>\... (via streamed from chatroom)
This is the console output from the one that is not working:
Started POST "/recipes/11/comments" for 127.0.0.1 at 2020-07-15 12:53:49 -0400
Processing by CommentsController#create as JS
Parameters: {"comment"=>{"description"=>"test comment"}, "commit"=>"Submit Comment", "recipe_id"=>"11"}
Chef Load (0.2ms) SELECT "chefs".* FROM "chefs" WHERE "chefs"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:11:in `current_chef'
Recipe Load (0.2ms) SELECT "recipes".* FROM "recipes" WHERE "recipes"."id" = ? ORDER BY "recipes"."updated_at" DESC LIMIT ? [["id", 11], ["LIMIT", 1]]
↳ app/controllers/comments_controller.rb:6:in `create'
(0.1ms) begin transaction
↳ app/controllers/comments_controller.rb:9:in `create'
Comment Create (0.3ms) INSERT INTO "comments" ("description", "chef_id", "recipe_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["description", "test comment"], ["chef_id", 1], ["recipe_id", 11], ["created_at", "2020-07-15 16:53:49.203129"], ["updated_at", "2020-07-15 16:53:49.203129"]]
↳ app/controllers/comments_controller.rb:9:in `create'
(50.3ms) commit transaction
↳ app/controllers/comments_controller.rb:9:in `create'
Rendered comments/_comment.html.erb (Duration: 1.7ms | Allocations: 1480)
[ActionCable] Broadcasting to comments: "<div class=\"row\">\n <div class=\"col-md-2\">\n <section class= \"chef_info center\">\n <img alt=\"john\" class=\"rounded-circle\" src=\"https://secure.gravatar.com/avatar/1c9e974c08914cda5ca2e7620c4fd3b6?s=60\" />\n </section> \n </div>\n\n <div class=\"comment col-md-8 card bg-light\">\n <p>test comment</p>\n <p class=\"quiet small\">Created: less than a minute ago by john</p>\n </div>\n</div>"
Completed 200 OK in 121ms (Views: 4.4ms | ActiveRecord: 52.0ms | Allocations: 23379)
The main difference is the last line ChatroomChannel transmitting while the other one doesnt have the equivelant. It seems the CommentChannel isn't transmitting after it has been created?
app/channels/application_cable/connection.rb:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_chef
def connect
self.current_chef = find_current_user
end
def disconnect
end
protected
def find_current_user
if current_chef = Chef.find_by(id: cookies.signed[:chef_id])
current_chef
else
reject_unauthorized_connection
end
end
end
end
app/channels/comments_channel.rb
class CommentsChannel < ApplicationCable::Channel
def subscribed
# stream_from "some_channel"
stream_from "comments"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
app/controllers/comments_controller.rb
class CommentsController < ApplicationController
#ensure current chef is available
before_action :require_user
def create
#recipe = Recipe.find(params[:recipe_id])
#comment = #recipe.comments.build(comment_params)
#comment.chef = current_chef
if #comment.save
ActionCable.server.broadcast "comments", render(partial: 'comments/comment', object: #comment)
#flash[:success] = "Comment was created successfully"
#redirect_to recipe_path(#recipe)
else
flash[:danger] = "Comment was not created"
redirect_back(fallback_location: root_path)
end
end
private
def comment_params
params.require(:comment).permit(:description)
end
end
app/javascript/comments_channel.js
import consumer from "./consumer"
consumer.subscriptions.create("CommentsChannel", {
connected() {
// Called when the subscription is ready for use on the server
},
disconnected() {
// Called when the subscription has been terminated by the server
},
received(data) {
// Called when there's incoming data on the websocket for this channel
return $("#messages").prepend(data);
}
});
app/views/recipes/show.html.erb:
<%= render "shared/page_title", title: #recipe.name %>
<div class="col-md-8 offset-md-2 card card-body bg-light">
<h4 class="center description"><strong>Steps: </strong></h4>
<hr/>
<%= simple_format(#recipe.description) %>
<hr/>
<% if #recipe.ingredients.any? %>
<p>Ingredients: <%= render #recipe.ingredients %> </p>
<% end %>
<div class="ml-auto">
<p class="center">
<em>Created by:</em>
</p>
<p class="center">
<%= link_to gravatar_for(#recipe.chef), chef_path(#recipe.chef) %>
</p>
<p class="center">
<small><%= #recipe.chef.chefname.capitalize %></small>
<div class="ml-auto"><%= time_ago_in_words(#recipe.created_at) %> ago</div>
</p>
</div>
<div class="recipe-actions">
<% if logged_in? && (current_chef == #recipe.chef || current_chef.admin?) %>
<%= link_to "Edit this recipe", edit_recipe_path(#recipe), class: "btn btn-xs btn-warning" %>
<%= link_to "Delete this recipe", recipe_path(#recipe), method: :delete,
data: {confirm: "Are you sure you want to delete this recipe?"}, class: "btn -btn-xs btn-danger" %>
<% end %>
<%= link_to "Return to recipes listing", recipes_path, class: "btn btn-xs btn-primary" %>
</div>
<%# add likes glyph icons here %>
</div>
<%# add nested route for comment %>
<% if logged_in? %>
<div class="row">
<div class="col-md-8 offset-md-2">
<h3>Comments: </h3>
<hr />
<%= form_for([#recipe, #comment], remote: true, :html => {class: "form-horizontal", role: "form"}) do |f| %>
<div class="row form-group">
<%= f.label :Comment, :class => 'control-label col-md-2' %>
<div class="col-md-8">
<%= f.text_area :description, rows: 8, class: "form-control", placeholder:"Enter comment here" %>
</div>
</div>
<div class="row form-group">
<div class="col-md-8 offset-md-2">
<%= f.submit "Submit Comment", class: "btn btn-primary btn-lg btn-xlarge" %>
</div>
</div>
<% end %>
<hr />
</div>
</div>
<% end %>
<%# if there are comments for this recipe, display them at the bottom %>
<% if #recipe.comments != 0 %>
<div class="row">
<div class = "col-md-8 offset-md-2">
<h3>Prior Comments: </h3>
<div id="messages">
<%= render partial: 'comments/comments', object: #comments %>
</div>
</div>
</div>
<% else %>
<div class="row">
<div class="col-md-8 offset-md-2">
<h3> No comments yet! </h3>
</div>
</div>
<% end %>
gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.6'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem 'bootstrap-sass', '~> 3.4.1'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
#add pagination to the site
gem 'will_paginate', '3.1.7'
#gem 'bootstrap-will_paginate', '~> 1.0'
gem 'will_paginate-bootstrap4'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
gem 'sqlite3', '~> 1.4'
gem 'rails-controller-testing'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
group :production do
gem 'pg'
gem 'redis'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Related

Ruby on Rails:{Form does not load template to registration#create when button submit is hit}

#This is the RegistrationCOntroller to link the Model to the Form so that the data can be placed and when it is submitted a message of thanks will appear
`
class RegistrationController < ApplicationController
def new
#user = User.new
end
def create
render plain: "Thanks"
end
end
#The Form Page
<div class = "d-flex align-items-center justify-content-center">
<h1> Registration </h1>
</div>
<%= form_with module: #user, url: sign_up_path do |form| %>
<div class = "mb-3">
<%= form.label :email%>
<%= form.text_field :email, class:"form-control", placeholder:"Exaple#gmail.com"%>
</div>
<div class = "mb-3">
<%= form.label :password%>
<%= form.password_field :password, class:"form-control", placeholder:"Password"%>
</div>
<div class = "mb-3">
<%= form.label :password_confirmation%>
<%= form.password_field :password_confirmation, class:"form-control", placeholder:"Password"%>
</div>
<div class = "mb-3">
<%= form.submit "Register", class:"btn btn-primary"%>
</div>
<% end %>
#The routes for the project and the post method for the registration
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
root to: "main#index"
get "about", to: "about#index"
get "sign_up", to: "registration#new"
post "sign_up", to: "registration#create"
end
`
#Note when the button is hit or the form is submitted no new page appears, and when i check the terminal for a response
Started POST "/sign_up" for 127.0.0.1 at 2022-11-13 08:49:52 -0400
Processing by RegistrationController#create as TURBO_STREAM
Parameters: {"authenticity_token"=>"[FILTERED]", "email"=>"test#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "commit"=>"Register"}
Rendering text template
Rendered text template (Duration: 0.1ms | Allocations: 10)
Completed 200 OK in 5ms (Views: 3.4ms | ActiveRecord: 0.0ms | Allocations: 963)
#Also if i remove the PlainText thanks from the Registration Create section i end up with this instead
Started POST "/sign_up" for 127.0.0.1 at 2022-11-13 08:53:52 -0400
Processing by RegistrationController#create as TURBO_STREAM
Parameters: {"authenticity_token"=>"[FILTERED]", "email"=>"test#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "commit"=>"Register"}
No template found for RegistrationController#create, rendering head :no_content
Completed 204 No Content in 2ms (ActiveRecord: 0.0ms | Allocations: 986)
#neither allows me to display my message on the post path "sign_up_path"
I tried renaming the routes path and trying various messages to display on the #create class object however I end up with the same result

Rails database error and incorrect message displayed - Online course on Upskill

After creating a form for the "contact us" page, I have validated the form to display "Message sent" and "Error occurred" when it is completed or left incomplete respectively.
Now when I fill the form properly and press submit, it shows "Error occurred" when it shouldn't.
This is what the terminal says when I press submit -
Started GET "/contacts/new" for 180.151.19.136 at 2020-09-08 20:25:29 +0000
Cannot render console from 180.151.19.136! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by ContactsController#new as HTML
Rendering contacts/new.html.erb within layouts/application
Rendered contacts/new.html.erb within layouts/application (2.1ms)
Completed 200 OK in 40ms (Views: 39.0ms)
Started POST "/contacts" for 180.151.19.136 at 2020-09-08 20:25:37 +0000
Cannot render console from 180.151.19.136! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by ContactsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"d6NOXW1mPMhhLExK/ltaYtCXWKykEcSXcGJv9O4eQ6NIDr9xmEDa+tqZmB0YdnThiydVWWoWGRGQ/8H9eR4ztw==", "contact"=>{"name"=>"okay okay"}, "commit"=>"Submit"}
(0.1ms) begin transaction
(0.0ms) rollback transaction
Redirected to https://dfb077768d054560bf89dc972cd52d7c.vfs.butt9.us-east-2.amazonaws.com/contacts/new
Completed 302 Found in 4ms
Started GET "/contacts/new" for 180.151.19.136 at 2020-09-08 20:25:38 +0000
Cannot render console from 180.151.19.136! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by ContactsController#new as HTML
Rendering contacts/new.html.erb within layouts/application
Rendered contacts/new.html.erb within layouts/application (3.0ms)
Completed 200 OK in 51ms (Views: 50.1ms)
This is my contact us page code, new.html.erb -
<div class="container">
<div class="row">
<h3 class="text-center">Contact Us</h3>
<div class="col-md-4 col-md-offset-4">
<%= flash[:notice] %>
<div class="well">
<%= form_for #contact do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.text_field :**name**, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments %>
<%= f.text_area :**name**, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default'%>
<% end %>
</div>
</div>
</div>
</div>
This is the contact.rb code -
class Contact < ActiveRecord::Base
validates :name, presence: true
validates :email, presence: true
validates :comments, presence: true
end
And this is the code on my controller file, contacts_controller.rb -
class ContactsController < ApplicationController
def new
#contact = Contact.new
end
def create
#contact = Contact.new(contact_params)
if #contact.save
redirect_to new_contact_path, notice: "Message sent."
else
redirect_to new_contact_path, notice: "Error occured."
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
This is the code I found on someone else's contacts_controller file following the same course -
class ContactsController < ApplicationController
# GET request to /contact-us
# Show new contact form
def new
#contact = Contact.new
end
# POST request /contacts
def create
# Mass assignment of form fields into contact object
#contact = Contact.new(contact_params)
# Save the Contact object to the database
if #contact.save
# Store form fields via parameters, into variables
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
# Plug variables into Contact Mailer
# email method and send email
ContactMailer.contact_email(name, email, body).deliver
# Store success method in flash hash
# and redirect to the new action
flash[:success] = "Message sent."
redirect_to root_path
else
# If Contact object doesn't save,
# render to the new action
render 'new'
end
end
private
# To collect data from form, we need to use
# strong parameters and white list form fields
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
All my work can be found here. Please let me know if you require any other information.
Thank you for your time and help.
EDIT 1 - So the error was in new.html.erb. f.text_field/area had
'name' instead of the respective label name.
I fixed that and used the code I provided above and it is working now.
try this
def create
#contact = Contact.new
if #contact.update(contact_params)
redirect_to new_contact_path, notice: "Message sent."
else
redirect_to new_contact_path, notice: "Error occured."
end
end
So the error was in new.html.erb. f.text_field/area had 'name' instead of the respective label name.
I fixed that by replacing 'name' with 'email' and 'comments' respectively and used the code I provided above and it is working now.

Can’t get a Middleman blog article summary?

This works fine:
<% blog.articles.each_with_index do |article, i| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<%= article.body %>
<% end %>
This does not:
<% blog.articles.each_with_index do |article, i| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<%= article.summary %>
<% end %>
Something about that summary throws an error:
TypeError: type mismatch: String given
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `=~'
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `default_summary_generator'
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:98:in `summary'
/Users/bob/Dropbox/Web Development/Projects/Middleman/BRP/source/index.html.erb:11:in `block (2 levels) in singleton class'
and so on...
Here's the part of my config.rb concerning the blog gem:
activate :blog do |blog|
# This will add a prefix to all links, template references and source paths
# blog.prefix = "blog"
# blog.permalink = "{year}/{month}/{day}/{title}.html"
# Matcher for blog source files
blog.sources = "posts/{year}-{month}-{day}-{title}.html"
# blog.taglink = "tags/{tag}.html"
# blog.layout = "layout"
blog.summary_separator = "==="
blog.summary_length = 250
# blog.year_link = "{year}.html"
# blog.month_link = "{year}/{month}.html"
# blog.day_link = "{year}/{month}/{day}.html"
# blog.default_extension = ".markdown"
blog.tag_template = "tag.html"
blog.calendar_template = "calendar.html"
# Enable pagination
blog.paginate = true
blog.per_page = 10
blog.page_link = "page/{num}"
end
# activate :directory_indexes
And my gemfile:
```
source 'http://rubygems.org'
Middleman Gems
gem "middleman", "~> 4.1.0"
gem "middleman-blog"
gem "middleman-livereload"
gem 'middleman-autoprefixer'
gem 'redcarpet', '~> 3.3', '>= 3.3.3'
For feed.xml.builder
gem "builder", "~> 3.0"
```
Where have I gone wrong?
Just a hunch, but blog.summary_separator = "===" looks like a troublemaker.
Try another string that couldn't be incorrectly interpreted as a comparison operator and see if it works.
Maybe try blog.summary_separator = /(READMORE)/
Don't forget to make that change in your post files as well. (Forgetting that sort of stuff is what makes me chase my tail more often than not.)
You don't really need to uncomment the two lines in config.rb:
blog.summary_separator = "==="
blog.summary_length = 250
Try adding this line below
<%= article.summary %>
<%= link_to 'Read more…', article %>

Ruby on Rails not detecting comment field

I'm trying to build a very basic Rails app for posting images with a comment. The comment is a required field and the image upload should only go ahead if the comments section has a value, displaying an error message otherwise.
The problem I am having is that even when the comments section is filled in it still displays an error saying that it cannot be blank.
I have tried adding attr_accessor's with the html field names and database values but it makes no difference.
Posts model
class Post < ActiveRecord::Base
has_attached_file :picture, styles: { medium: "300x300>", thumb: "100x100>" }
attr_accessor :picture_file_name
attr_accessor :post_description
validates :description, presence: true
end
Posts controller
class PostsController < ApplicationController
def index
#posts = Post.all
end
def new
#post = Post.new
end
def create
#post = Post.new params[:post].permit(:description, :picture)
if #post.save
redirect_to '/posts'
else
render 'new'
end
end
end
new.html.erb
<% 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 %>
<%= form_for #post, :html => { :multipart => true } do |f| %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.label :picture %>
<%= f.file_field :picture %>
<%= f.submit %>
<% end %>
Server readout
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-04-20 17:59:07] INFO WEBrick 1.3.1
[2014-04-20 17:59:07] INFO ruby 2.1.0 (2013-12-25) [x86_64-darwin12.0]
[2014-04-20 17:59:07] INFO WEBrick::HTTPServer#start: pid=98772 port=3000
Started POST "/posts" for 127.0.0.1 at 2014-04-20 17:59:21 +0100
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nVrCEAdT+epbltQWR74jtv1weGaq6H7YbWQKFfJNDTw=", "post"=>{"description"=>"test comment", "picture"=>#<ActionDispatch::Http::UploadedFile:0x0000010242f740 #tempfile=#<Tempfile:/var/folders/lm/vrw53rx91831vrh4228m0mfw0000gn/T/RackMultipart20140420-98772-1c9msrz>, #original_filename="dory_2.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"post[picture]\"; filename=\"dory_2.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Post"}
WARNING: Can't mass-assign protected attributes for Post: description, picture
app/controllers/posts_controller.rb:12:in `create'
(0.1ms) begin transaction
(0.1ms) rollback transaction
Rendered posts/new.html.erb within layouts/application (13.1ms)
Completed 200 OK in 105ms (Views: 65.6ms | ActiveRecord: 0.4ms)
Your params & form look okay
But I would change your strong params to be more conventional:
def create
#post = Post.new(post_params)
#post.save
end
private
def post_params
params.require(:post).permit(:description, :picture)
end
I found the problem.
The issue was that I had originally installed the latest version of Paperclip and then downgraded.
I had added the following gem while I was searching for a solution
gem 'protected_attributes'
This was causing all required fields not to register they were being filled in, such as in user sign up fields etc.
Once that gem was removed it worked just fine.

Twitter bootstrap sass not working on some pages

I've installed the bootstrap-sass gem and I am finding the css works on some pages and not others, which I am not sure why this is.Below I've included the views in which it's not working, the Gemfile and the stylesheets.
gemfile:-
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'pg', '~> 0.15.1'
gem "bcrypt-ruby", '~> 3.0.1'
gem "paperclip", '~> 3.4.2'
gem "will_paginate", '~> 3.0.4'
gem "friendly_id", '~> 4.0.9'
gem 'stripe'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass', '~> 2.3.2'
end
group :test do
gem 'rspec-rails', '2.13.2'
gem 'factory_girl_rails', '~> 4.2.1'
gem 'capybara', '~> 2.1'
gem 'launchy', '~> 2.3'
gem 'guard-rspec', '~> 3.0.1'
gem 'shoulda-matchers', '~> 2.1'
gem 'webmock'
end
group :development do
gem 'annotate', ">=2.5.0"
end
group :test, :development do
gem 'database_cleaner'
gem 'rspec-rails', '2.13.2'
gem 'guard-rspec', '~> 3.0.1'
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
gem 'fuubar', '~> 1.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails', '~> 3.0.1'
application.css.scss:-
*= require_self
*= require_tree .
*/
#import "bootstrap";
baskets.html.erb
<p><%= notice %></p>
<p><%= #basket_items.product_totals %><p>
<%= button_to "Purchase products", new_payment_path, :class => "btn" %>
<table class="table table-hover">
<tr>
<th>Picture</th>
<th>Name</th>
<th>Price</th>
<th></th>
</tr>
<tr>
<% #basket_items.each do |item| %>
<td><p>Nothingness</p></td>
<td><p><%= item.product.name %></p></td>
<td><p><%= item.product.price %></p></td>
<td><%= button_to 'Remove', basket_item_path(item.id), :method => 'delete', :confirm => 'Are you sure?', :class => "btn" %></td>
<% end %>
</tr>
</table>
categories show
show.html.erb
<button type="button" class="close" data-dismiss="alert">×</button>
<p><%= flash[:notice] %></p>
<div class="search">
<%= form_tag(search_path, method: "get", :class => "form-search") do %>
<%= text_field_tag(:query, nil, :class => "input-medium search-query") %>
<%= submit_tag("Search", :class => "btn") %>
<% end %>
</div>
<div class="container-fluid">
<div class="row-fluid">
<% #cp.each do |p| %>
<div class="product">
<div class="product-image">
<%= image_tag p.image %>
</div>
<p><%= p.price %></p>
<p><%= link_to p.name, product_path(p.slug) %></p>
<% end %>
</div>
</div>
</div>
categories.css.scss
.product {
display: inline-block;
}
.product-image {
width: 40px;
height: 50px;
}
.row-fluid {
margin-top: 300px;
}
.search {
margin: 100px 10px 0px 0px;
}
It would help if you could be more specific than "not working", but generally if assets aren't loading correctly or older versions of assets are showing instead, there is good chance you forgot to precompile your assets.
Try running bundle exec rake assets:precompile, then reload the page.
I had a similar problem. For me it was because I had an assets folder in my vendor directory, and within that a stylesheets folder. I assume that rails checked those folders for bootstrap because they existed instead of importing the bootstrap gem? Once I deleted those it worked perfectly.