Updating to 3.1.1 following RailsTutorial.org screencast - ruby-on-rails

I am following the lesson 13 screencast from Railstutorial.org and am hung up on the error below:
Failures:
1) PagesController GET 'home' when signed in should have the right follower/following counts
Failure/Error: response.should have_selector('a', :href => following_user_path(#user),
expected following output to contain a <a href='/users/1/following'>0 following</a> tag:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ruby on Rails Tutorial Sample App | Home</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--><link href="/assets/blueprint/screen.css" media="screen" rel="stylesheet" type="text/css">
<link href="/assets/blueprint/print.css" media="print" rel="stylesheet" type="text/css">
<!--[if lt IE 8]><link href="/assets/blueprint/ie.css" media="screen" rel="stylesheet" type="text/css" /><![endif]--><link href="/assets/custom.css" media="screen" rel="stylesheet" type="text/css">
<script src="/assets/defaults.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<header><img alt="Sample App" class="round" src="/assets/logo.png">
<nav class="round"><ul>
<li> Home
</li>
<li> Help
</li>
<li> Sign in
</li>
</ul></nav></header><section class="round"><h1>Home</h1>
<p>Find me in app/views/pages/home.html.erb</p>
Sign up now!
</section><footer><nav class="round"><ul>
<li> About </li>
<li> Contact </li>
<li> News </li>
<li> About </li>
</ul></nav></footer>
</div>
</body>
</html>
# ./spec/controllers/pages_controller_spec.rb:119:in `block (4 levels) in <top (required)>'
Finished in 7.32 seconds
10 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:117 # PagesController GET 'home' when signed in should have the right follower/following counts
my gemfile:
source 'http://rubygems.org'
gem 'rack' , '1.3.3'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'gravatar_image_tag', '1.0.0.pre2'
# gem 'will_paginate', '3.0.pre2'
gem 'will_paginate', '~> 3.0.2'
gem 'sqlite3', '1.3.4'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :development do
gem 'rspec-rails', '2.7.0'
# gem 'annotate-models', '1.0.4'
gem 'annotate', '2.4.0'
gem 'faker', '0.3.1'
end
group :test do
gem 'rspec-rails', '2.7.0'
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc8'
gem 'factory_girl_rails', '1.0'
# gem 'autotest', '4.4.6'
# gem 'autotest-rails-pure', '4.1.2'
# gem 'autotest-fsevent', '0.2.4'
# gem 'autotest-growl', '0.2.9'
end
Wondering possibly if its an rspec version problem? --
pages_controller_spec.rb
it "should have the right follower/following counts" do
get :home
response.should have_selector('a', :href => following_user_path(#user),
:content => "0 following")
response.should have_selector('a', :href => followers_user_path(#user),
:content => "1 follower")
end
pages_controller.rb
class PagesController < ApplicationController
def home
#title = "Home"
if signed_in?
#micropost = Micropost.new
#feed_items = current_user.feed.paginate(:page => params[:page])
end
end
def contact
#title = "Contact"
end
def about
#title = "About"
end
def help
#title = "Help"
end
end
when I comment out the pages_controller_spec.rb section I go green
Any thoughts?
Update 1:
Changing RSPEC versions did not work, tried 2.4.0, 2.6.1 and 2.6.4
Update 2:
Changing to Rails 3.1.0 did not work
Update 3:
Triple Checked running rspec in original sample app Rails 3.0.8 GREEN
update 4:
home page
<% if signed_in? %>
<table class="front" summary="For signed-in users">
<tr>
<td class="main">
<h1 class="micropost"> What's up? </h1>
<%= render 'shared/micropost_form' %>
<%= render 'shared/feed'%>
</td>
<td class="sidebar round">
<%= render 'shared/user_info' %>
<%= render 'shared/stats' %>
</td>
</tr>
</table>
<% else %>
<h1>Home</h1>
<p>Find me in app/views/pages/home.html.erb</p>
<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %>
<% end %>

The error message suggests that when a user visits /pages/home they should see a link constructed from the following code:
<a href='/users/1/following'>0 following</a>
Do you actually see that link when you visit the home page?
If not, then you should add it, I'd imagine there's a section or chapter where the author walks you through doing that.

Related

Rails Create Method Creating Duplicates

I have a to do list function in my app which appears to be creating duplicate tasks every time I try to enter one. (You can see the error live at https://www.thestaysanemom.com/tasks with the username 'test#test.com' and password of 'password'.)
The app uses ajax to function, which I can only imagine is causing the error.
The create method is like this:
def create
#task = Task.new(task_params)
#task.user_id = current_user.id
if #task.save
respond_to do |format|
format.js
format.html
end
else
render :new
end
end
Here's the view where it all takes place:
<% if current_user %>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-12">
<div class="content-box to-do">
<h2 class="font-script text-center">One-Time Tasks</h2>
<p class="text-center">These tasks are here to stay, until you complete them.</p>
<div id="onetime-todo"><%= render partial: 'items', locals: { task: #one_time } %></div>
<div id="onetime-done"><%= render partial: 'done', locals: { task: #one_time_done } %></div>
</div> <!-- content box -->
</div> <!-- col -->
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="content-box to-do">
<h2 class="font-script text-center">Daily</h2>
<p class="text-center">These automatically uncheck at night so you have a fresh list in the morning.</p>
<div id="daily-todo"><%= render partial: 'items', locals: { task: #daily } %></div>
<div id="daily-done"><%= render partial: 'done', locals: { task: #daily_done } %></div>
</div> <!-- content box -->
</div> <!-- col -->
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="content-box to-do">
<h2 class="font-script text-center">Weekly</h2>
<p class="text-center">These automatically uncheck Sunday night so you get a new list each Monday morning.</p>
<div id="weekly-todo"><%= render partial: 'items', locals: { task: #weekly } %></div>
<div id="weekly-done"><%= render partial: 'done', locals: { task: #weekly_done } %></div>
</div> <!-- content box -->
</div> <!-- col -->
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="content-box to-do">
<h2 class="font-script text-center">Monthly</h2>
<p class="text-center">These automatically uncheck on the last day of the month so you start with a clean list each 1st.</p>
<div id="monthly-todo"><%= render partial: 'items', locals: { task: #monthly } %></div>
<div id="monthly-done"><%= render partial: 'done', locals: { task: #monthly_done } %></div>
</div> <!-- content box -->
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<% end %> <!-- current_user -->
<script>
$(document).ready(function() {
$('.content-box').matchHeight();
});
</script>
Here's my create.js.erb:
$("#onetime-todo").html("<%= escape_javascript(render partial: 'items', locals: { task: #one_time }) %>")
$("#onetime-done").html("<%= escape_javascript(render partial: 'done', locals: { task: #one_time_done }) %>")
$("#daily-todo").html("<%= escape_javascript(render partial: 'items', locals: { task: #daily }) %>")
$("#daily-done").html("<%= escape_javascript(render partial: 'done', locals: { task: #daily_done }) %>")
$("#weekly-todo").html("<%= escape_javascript(render partial: 'items', locals: { task: #weekly }) %>")
$("#weekly-done").html("<%= escape_javascript(render partial: 'done', locals: { task: #weekly_done }) %>")
$("#monthly-todo").html("<%= escape_javascript(render partial: 'items', locals: { task: #monthly }) %>")
$("#monthly-done").html("<%= escape_javascript(render partial: 'done', locals: { task: #monthly_done }) %>")
$('#textField').val("");
Which renders _items.html.erb:
<div class="to-do-list taskWrapper" data-url="<%= sort_tasks_path %>">
<% task.each do |task| %>
<div id="<%= dom_id(task) %>">
<%= link_to task do %>
<p>
<%= fa_icon "bars", class: "color-neutral-light", style: "margin-right: 5px;" %>
<%= link_to check_task_path(task), method: :post, remote: true do %>
<%= fa_icon "square-o", style: "margin-right: 5px;" %>
<% end %>
<span id="task-show-hide">
<span class="font-serif">
<%= task.name %>
</span>
<span>
<%= link_to task_path(task), method: :delete, remote: true do %>
<%= fa_icon "remove", id: (task.id.to_s + "task"), style: "margin-left: 5px" %>
<% end %>
</span>
</span>
</p>
<% end %> <!-- dom id wrapper -->
</div>
<% end %> <!-- task each -->
</div>
<script>
$(document).on('ready page:load', function() {
$('.content-box').matchHeight();
$(".taskWrapper").sortable({
update: function(e, ui) {
var $that = $(e.target);
Rails.ajax({
url: $(this).data("url"),
type: "PATCH",
data: $that.sortable('serialize'),
});
console.log(ui.item.index())
}
});
});
</script>
And I don't think it matters, but for completion's sake here's the schema for tasks.
create_table "tasks", force: :cascade do |t|
t.string "name"
t.string "frequency"
t.boolean "completed", default: false
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "position"
t.index ["user_id"], name: "index_tasks_on_user_id"
end
Can anyone see why this is creating duplicates?
Additional Info: ERB Form Creation
<%= simple_form_for(#create_task, remote: true) do |f| %>
<div class="row padded">
<div class="col-xs-12 col-sm-9">
<%= f.text_field :name, id: "textField", placeholder: "What needs to get done?", class: "form-control" %>
</div>
<div class="col-xs-12 col-sm-3">
<%= f.select :frequency, options_for_select([["One-Time", "OneTime"],["Daily", "Daily"],["Weekly", "Weekly"],["Monthly", "Monthly"]]), {}, {class: "form-control"} %>
</div>
<div class="container text-center">
<div class="half-buffer"></div>
<%= f.button :submit, class: "btn btn-outline-secondary" %>
<div class="half-buffer"></div>
</div>
</div> <!-- row -->
<% end %>
ADDITIONAL INFORMATION
As requested, here are my required statements inside my application.js.erb:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require popper
//= require magnific-popup
//= require jquery-ui
//= require froala_editor.min.js
//= require plugins/align.min.js
//= require plugins/char_counter.min.js
//= require plugins/code_beautifier.min.js
//= require plugins/code_view.min.js
//= require plugins/colors.min.js
//= require plugins/font_size.min.js
//= require plugins/fullscreen.min.js
//= require plugins/image.min.js
//= require plugins/image_manager.min.js
//= require plugins/inline_style.min.js
//= require plugins/line_breaker.min.js
//= require plugins/link.min.js
//= require plugins/lists.min.js
//= require plugins/paragraph_format.min.js
//= require plugins/paragraph_style.min.js
//= require plugins/quote.min.js
//= require plugins/special_characters.min.js
//= require plugins/url.min.js
** ADDED GEMFILE **
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.0'
gem 'rails', '~> 5.2.0'
gem 'puma', '~> 3.11'
gem 'puma_worker_killer'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jbuilder', '~> 2.5'
gem 'mini_magick'
gem 'jquery-rails'
gem 'devise'
gem 'bootsnap'
gem 'bootstrap', '~> 4.1.3'
gem 'jquery-ui-rails'
gem 'sprockets-rails'
gem 'bootstrap-sass'
gem 'bcrypt', '~> 3.1.7'
gem 'friendly_id', '~> 5.2.0'
gem 'stripe'
gem 'figaro'
gem 'magnific-popup-rails', '~> 1.1.0'
gem 'simple_form'
gem 'acts-as-taggable-on', '~> 6.0' #must be this version for Rails5
gem 'aws-sdk' , '~> 3'
gem 'aws-sdk-s3', require: false
gem 'simple_form_extension'
gem 'recaptcha', require: "recaptcha/rails"
gem 'font-awesome-rails'
gem 'trix-rails', require: 'trix'
gem 'rack-tracker'
gem 'high_voltage', '~> 3.1'
gem 'convertkit-ruby', require: 'convertkit'
gem 'dotenv-rails'
gem 'acts_as_list'
gem 'wysiwyg-rails'
gem 'font-awesome-sass'
gem 'will_paginate'
group :production do
gem 'pg', '~> 0.20.0'
end
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'sqlite3'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'binding_of_caller'
gem 'better_errors'
end
group :test do
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Your rails code looks fine, but your form is getting double-submitted when you submit. You should be able to see this in the Chrome dev tools as below.
Both of those references point to the application.js file, but different lines. It's hard to tell which libraries are catching the submit because the file is concatenated and doesn't include the debug information. Without seeing which JS files you're using (from application.js), I'd venture a guess that you might have both rails-ujs & jquery_ujs included which is causing the double submit.
Check the related question and answers here: Form submitted twice, due to :remote=>true
Update: You've definitely got both rails-ujs & jquery_ujs present in your compiled JS file. I think that's a good place to look. If you're on Rails 5 and using the jquery-rails gem you might look here: https://github.com/rails/jquery-rails#installation
If you are running Rails 5.1 and up, and if you have
included //= require rails-ujs, then jquery_ujs is not needed anymore
You just need to remove the //= require jquery_ujs line from your app/assets/javascripts/appplication.js file

Rspec capybara webkit cant find button tag

I have the following test
require "rails_helper"
RSpec.feature "Menu", :type => :feature do
let!(:articles) { create_list(:article, 10) }
let!(:quotes) { create_list(:quote, 2) }
before { visit "/" }
scenario "should not have Javascript errors" do
Capybara.current_driver = :webkit
page.find("#menu-button").click
expect(page).not_to have_errors
end
end
and it fails with the message
Capybara::ElementNotFound:
Unable to find css "#menu-button"
I also tried
click_on "Open Menu"
click_button "Open Menu"
click_link "Open Menu"
page.find_button(id: 'menu-button').click
find("#menu-button").click
I am trying to test the off canvas feature that foundation 6 has.
application.html.erb file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "Stargazers.news" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="off-canvas-wrapper">
<div class="off-canvas position-left" id="offCanvas" data-off-canvas>
<button class="close-button" arial-label="Close menu" type="button" data-close></button>
<div id="search">
<%= form_tag({controller: "/pages", action:"search"}, method: "get") do %>
<%= label_tag(:search, "Search for:") %>
<%= text_field_tag(:search) %>
<%= submit_tag("Search") %>
<% end %>
</div>
</div>
<div class="off-canvas-content" data-off-canvas-content>
<div class="top-bar">
<div class="top-bar-right">
<button id="menu-button" type="button" class="button" data-toggle="offCanvas">Open Menu</button>
</div>
</div>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</div>
</div>
</body>
</html>
the index.html.erb file
<div id="quote">
<%= #quote.body %>
</div>
<% #articles.each do |article| %>
<article>
<header> <%= article.title%> </header>
<div class="content-summary"> <%= article.body %> </div>
</article>
<hr/>
<% end %>
rails_helper.rb file
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
require 'simple_bdd/rspec'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
Capybara.javascript_driver = :webkit
config.include FactoryGirl::Syntax::Methods
config.include RSpecHtmlMatchers
config.include Devise::Test::IntegrationHelpers, type: :feature
config.use_transactional_fixtures = true
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.0.1'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'foundation-rails'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem "paperclip", "~> 5.0.0"
gem 'devise'
group :development, :test do
gem 'byebug', platform: :mri
gem 'factory_girl_rails'
gem 'rspec-rails', '~> 3.5'
gem 'rspec-html-matchers'
gem 'ffaker'
gem 'simple_bdd'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem "better_errors"
end
group :test do
gem 'capybara-webkit'
gem 'database_cleaner'
gem 'shoulda-matchers', '~> 3.1'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
my qt version is 5.5.1
and I am on Ubuntu 16.04
By default Capybara doesn't find non-visible elements, and 99% of the time it can't interact with a non-visible element. This is because it's designed to emulate a users behavior and a user can't interact with something they can't see on the page.
UPDATE: now that you've included the whole test the issue is clearer. You're not setting the test to use :webkit until after the visit '/' has occurred. This means the :racktest driver visits the page but then you swap to the :webkit driver which hasn't actually loaded any page, so there is nothing there. Rather than manually setting current_driver in the test you should just be tagging the test with js: true (or driver: :webkit) metadata
scenario "should not have Javascript errors", js: true do
...
end
That will then set the current driver to the value of Capybara.javascript_driver (which you've set to :webkit) before the visit occurs.
Additionally your database_cleaner setup is lacking a bit - it should be the suggested setup - https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example - The swap from after to append_after is important for test stability and the checks for driver type will help speed up your tests.
Finally, there is no need to specify :type => :feature if you're already using RSpec.feature
Try adding visible: false to your find call, like this:
page.find("#menu-button", visible: false).click

Rails 5 No template found error

Error in terminal while running rails s:
Started POST "/users/confirm" for ::1 at 2017-01-28 15:12:30 -0600
Processing by UsersController#confirm as HTML
No template found for UsersController#confirm, rendering head :no_content
It seems that this is actually an Unknown Format error in rails that is passing as a 204 No Content error. I am really new to rails, and doing this for a course.
I have a controller with one def confirm action. It isn't repeated anywhere in my file. Unlike most of the posts previous there isn't a respond_to method located within this action.
Where does the error actually stem from? I don't know if I should be looking at config or re-working the controller
This is my gemfile:
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.1'
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
gem 'pry-rails'
end
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'shoulda'
gem 'rails-controller-testing'
end
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'listen'
gem 'bootstrap-sass'
gem 'bcrypt'
edit.html.erb
<h1>Sign Up Confirmation</h1>`
<div class="row">
<div class='col-md-2'>
<h3>Are you sure these values are correct?</h3>
<h5>Name: <% #user.name %></h5>
<h5>Email: <% #user.email %></h5>
</div>
</div>
<div class="row">
<div class="col-md-2", style="width: auto;">
<%= button_to "Yes", {controller: "users",
action: "create", params: params}, class: 'btn btn-success' %>
</div>
<div class="col-md-2", style="width: auto;">
<%= link_to "No", new_user_path, class: 'btn btn-default' %>
</div>
</div>
It looks like you're missing a confirm.html.erb file in your views/users directory. Rails looks for a view file to render when a action is called, and it's looking for a file with the same name as the action.
If you haven't already, create that file, save and refresh the page. The error should be gone. The page will be blank unless you populate the file with some HTML, but from here you should be good to go.

Rails/devise app not working properly on Heroku due to new_user_registration_path

Hope one of you can help me out on this one, since I've been breaking my head on it for a while.
I deployed my app to Heroku after trying it out on the cloud9 preview.
The problem is that whenever I try to press the button to create a account for a paid subscription, I don't get linked to the page to fill in my credentials. However, on cloud9 this seems to be working fine.
I found the the sole difference between the two by hovering over the same buttons on the different platforms with my mouse.
On cloud9 I get: https://xxxxxxxx-xxxxx.xxxxxxx.xx/users/sign_up?plan=1
On Heroku I get: https://xxxxxxxx-xxxx-xxxxx.herokuapp.com/sign_up
So whenever I click the one on Heroku, I get my build-in flash message saying: Please select a membership plan to sign up!
To be more specific whereas the problem lies according to me, I think it's somewhere in the home.html.erb where the variable gets passed through. (added below)
So it seems that the routing isn't working correct on my Heroku, but I just can't figure out why. I've added my files below.
Hope someone can help me out on this one!
Kind regards.
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]
# Use postgresql as the database for production
group :production do
gem 'pg'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
### ADDED GEMS ###
# Bootstrap Gem
gem 'bootstrap-sass', '~> 3.3.6'
# Devise Gem
gem 'devise'
# Font Awesome
gem 'font-awesome-rails'
# Use stripe for handling payments
gem 'stripe'
# Use figaro to hide secret keys
gem 'figaro'
ruby '2.3.0'
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'users/registrations' }
resources :users do
resource :profile
end
resources :contacts
get '/about' => 'pages#about'
root 'pages#home'
end
pages_controller.rb
class PagesController < ApplicationController
def home
#trial_plan = Plan.find_by id: '1'
#pro_plan = Plan.find_by id: '2'
end
def about
end
end
users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :select_plan, only: :new
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_payment
else
resource.save
end
end
end
end
private
def select_plan
unless params[:plan] && (params[:plan] == '1' || params[:plan] == '2')
flash[:notice] = "Please select a membership plan to sign up."
redirect_to root_url
end
end
end
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Ayris</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag "https://js.stripe.com/v2/", type: 'text/javascript' %>
<%= javascript_include_tag 'application' %>
<%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %>
<%= csrf_meta_tags %>
</head>
<body>
...
<%= link_to root_path, class: 'navbar-brand' do %>
<i class="fa fa-users"></i>
Ayris
<% end %>
...
<% if user_signed_in? %>
...
<% else %>
...
<% if user_signed_in? %>
...
<% end %>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact Us", new_contact_path %></li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</nav>
<div class="container">
<% flash.each do |key, value| %>
<%= content_tag :div, value, class: "alert alert-#{key}" %>
<% end %>
<%= yield %>
</div>
</body>
</html>
home.html.erb
<% if user_signed_in? %>
...
<% if current_user.profile %>
...
<% else %>
...
<% end %>
...
<% else %>
<div class="col-md-6">
<div class="well">
<h2 class="text-center">Trial Membership</h2>
<h4>Sign up for free and get trial access for a period of 10 days.</h4>
<br/>
<%= link_to "Sign up for Trial", new_user_registration_path(plan: #trial_plan), class: 'btn btn-primary btn-lg btn-block' %>
</div>
</div>
<div class="col-md-6">
<div class="well">
<h2 class="text-center">Pro Membership</h2>
<h4>Sign up for the pro account for €75/month and get access to all functions.</h4>
<%= link_to "Sign up for Pro", new_user_registration_path(plan: #pro_plan), class: 'btn btn-success btn-lg btn-block' %>
</div>
</div>
<% end %>
</div>
I fixed the problem, the thing you've mentioned about the database was right. The problem was that, for some reason, the db migration to Heroku was unsuccessful, without giving me any notice about it. After running:
Heroku run rails c
Plan.create(name: 'trial', price: 0)
Plan.create(name: 'pro', price: 75)
After running these commands the both plans were injected to the database of my Heroku app. My code seems to work perfectly fine now, altough I've changed the following piece of code according to your comment about hardcoding ID's
pages_controller.rb
class PagesController < ApplicationController
def home
if Plan.find_by name: 'trial'
#trial_plan = 1
end
if Plan.find_by name: 'pro'
#pro_plan = 2
end
end
end
Thanks for the heads up.

Twitter bootstrap issue using Ruby on Rails

Can anybody please solve me one issue regarding bootstrap using in ROR.
Issue:
I have integrated gem "'bootstrap-sass', '3.2.0.2'" in my gem file.After adding some bootstrap navigation code in application.html.erb,it is showing one nice bootstrap navigation bar.If i am doing some changes in style sheet and refreshes the page it is splitting means the nav menu lists is not coming in inline and next time onward it is repeating.Actually i want the original nav bootstrap bar even if I did any changes in style sheet.
Please check my below code snippets and make it correct.
My codes are as follows:
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.19'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'bootstrap-sass', '3.2.0.2'
homes.css.scss
#import "bootstrap-sprockets";
#import "bootstrap";
body {
padding-top: 60px;
}
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>LibraryManagement</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<header class="navbar navbar-fixed-top navbar-default">
<div class="container">
<%= link_to "Library Management System", '#', id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Books", '#' %></li>
<li><%= link_to "Member Entry", '#' %></li>
<li><%= link_to "Admin Login", '#' %></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<%= yield %>
</div>
</body>
</html>
homes/index.html.erb
<h1>Index page</h1>
Please help me.Thanks in advance.

Resources