Redirect to template not working after Foundation Framework installation

129 views Asked by At

On my local host after having rails create a new object in the database (through a controller) I used to have my app render a template (if @object.save returns true). After installing zurb foundation the template doesn't show and neither does my flash message, the new object Investor is also not being created at all. The logs doesn't make much sense to me. Any help here?

generated html form

<form div class="small-6 large-centered columns">
    <fieldset>
        <legend> Enter your best details</legend>
<form class="new_investor" id="new_investor" action="/investors" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><input type="hidden" name="authenticity_token" value="Ipbkx9oO1mWplLMXhCZA8q7nbgHr4jm9Y7BHHzLryV2va0qHzY1W04ifxu2sPHm6Iz0r7+7ZPwMsyE8sfWpiLg==" />



    <label for="investor_name">Name</label>
    <input placeholder="John Doe" type="text" name="investor[name]" id="investor_name" /> </br>

    <label for="investor_email">Email</label>
    <input placeholder="[email protected]" type="text" name="investor[email]" id="investor_email" /></br>

    <label for="investor_country">Country</label>
    <input type="text" name="investor[country]" id="investor_country" /></br>

    <label for="investor_phone">Phone</label>
    <input placeholder="+48000000" type="text" name="investor[phone]" id="investor_phone" /></br>

    <input type="submit" name="commit" value="I&#39;m interested!" class="button radius" />
</form> </fieldset>
<form>

routes

siaw ~/Desktop/ps/forex $ rake routes
              Prefix Verb   URI Pattern                     Controller#Action
                root GET    /                               investors#index
static_pages_welcome GET    /static_pages/welcome(.:format) redirect(301, static_pages/welcome.html)
           investors GET    /investors(.:format)            investors#index
                     POST   /investors(.:format)            investors#create
        new_investor GET    /investors/new(.:format)        investors#new
       edit_investor GET    /investors/:id/edit(.:format)   investors#edit
            investor GET    /investors/:id(.:format)        investors#show
                     PATCH  /investors/:id(.:format)        investors#update
                     PUT    /investors/:id(.:format)        investors#update
                     DELETE /investors/:id(.:format)        investors#destroy

new.html.erb

<form div class="small-6 large-centered columns">
    <fieldset>
        <legend> Enter your best details</legend>
<%= form_for(@investor) do |f| %>

 <%= render 'shared/error_messages', object: f.object %>

    <%= f.label :name %>
    <%= f.text_field :name, :placeholder => "John Doe" %> </br>

    <%= f.label :email %>
    <%= f.text_field :email, :placeholder => "[email protected]" %></br>

    <%= f.label :country %>
    <%= f.text_field :country %></br>

    <%= f.label :phone %>
    <%= f.text_field :phone, :placeholder => "+48000000000" %></br>

    <%= f.submit "I'm interested!", :class => 'button radius' %>
<% end %>
    </fieldset>
<form>

routes.rb

Rails.application.routes.draw do

  root 'investors#index'
  get '/static_pages/welcome', :to => redirect('static_pages/welcome.html')

  resources :investors

end

inverstors_controller.rb

class InvestorsController < ApplicationController
  def index
    @investor = Investor.first
  end

  def show
    @investor = Investor.find(params[:id])
  end

  def new
    @investor = Investor.new
  end

  def create
    @investor = Investor.new(user_params)
    if @investor.save
        flash[:success] = "Welcome, you're now on your way to success!"
        redirect_to "static_pages/welcome"
      InvestorMailer.welcome_email(@investor).deliver_now
    else
        render 'new'
    end
  end

  def update
    if @investor.update_attributes(user_params)
        flash[:success] = "Updated"
    else
        render 'edit'
    end
  end

  private

    def user_params
      params.require(:investor).permit(:name, :email, :country,
                                   :phone)
    end
end

application.html.erb

<!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) : "Smart Investor Club" %></title>

    <%= stylesheet_link_tag    "application" %>
    <%= javascript_include_tag "vendor/modernizr" %>
    <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
  </head>

  <body>
    <div class="row">
  <% flash.each do |name, msg| %>
    <% if msg.is_a?(String) %>
      <%= content_tag :div, msg, class: "alert-box #{name} radius" %>
    <% end %>
  <% end %>
</div>


    <%= yield %>

  </body>
</html>

_error_messages.html.erb

<% if object.errors.any? %>
  <div>
    <div>
      The form contains <%= pluralize(object.errors.count, "error") %>.
    </div>
    <ul>
    <% object.errors.full_messages.each do |msg| %>
      <li data-alert class="alert-box warning round"><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>

logs

Started GET "/" for ::1 at 2015-06-12 02:17:12 +0200
  ActiveRecord::SchemaMigration Load (0.3ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by InvestorsController#index as HTML
  Investor Load (0.5ms)  SELECT  "investors".* FROM "investors"  ORDER BY "investors"."id" ASC LIMIT 1
   (0.3ms)  SELECT COUNT(*) FROM "investors"
  CACHE (0.0ms)  SELECT COUNT(*) FROM "investors"
  Rendered investors/index.html.erb within layouts/application (2.6ms)
Completed 200 OK in 382ms (Views: 359.3ms | ActiveRecord: 2.9ms)


Started GET "/assets/foundation_and_overrides.self-464f93cbdaa7634d29f2bb979d2132db759337852a741d1de08d9aa3b85ed35e.css?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/investor.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/application.self-489c3e007974fbfaa496637ac1204061ef9d39f4dd29f1f5d1eae0ed61b80625.css?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/vendor/modernizr.self-74da3245def7569da28115667be6a85a2ad97464abe707c9829c46d8975597bc.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/jquery.self-d03a5518f45df77341bdbe6201ba3bfa547ebba8ed64f0ea56bfa5f96ea7c074.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.self-ee5396739ce46beb039f26ea629172a74143752d74f703c6c3b219fc52aecf73.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/jquery_ujs.self-8e98a7a072a6cee1372d19fff9ff3e6aa1e39a37d89d6f06861637d061113ee7.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.abide.self-f8b56c707a79139807305a5f7efc2aaa0848f0c677abcc056496f507e0192b79.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.accordion.self-d55abdcb0a7a29512be2f31f63d418cc8cc4505a0a3c71946d25484b0a0b3f4e.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.alert.self-fbde7afb61e8ffd8ab9b717f0bed1e58cb9e0144a25cc773fea634d5554f62cd.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.clearing.self-54610737b435a97590fcb176848c3c7a44c4d55d369894260fa7c28c97a70a23.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.dropdown.self-c9ee29909e266373e5e814a73fc6ea062245ddd29466d35d232448f73350d78a.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.equalizer.self-7aa743bf4660deb2fb2f601c112806a1703c430067531da3f41e4afffe19fee9.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.interchange.self-dad8415355087cb21a16fa44bac20d602344d52de5aca9e588e3588fce5dd5a7.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.joyride.self-0a5271728699423f583dd5b3b8a11bfe0dc9fb5044446bcf3218ef8ca906a82d.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.magellan.self-a50193f172f11e57b373c3001072ba2d6b34b857ab251e9ded30af5242855687.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.offcanvas.self-75bffd0c7f4f0d2992ab95f0cc6959282ebb5807da70123d40c01d76e230ec88.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.orbit.self-f8d30eb1717c874db26723f9e07901ec0a325d59263f1404ee83a616bb597ad2.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.reveal.self-95f01feb3e25e47b58b78da0021ae2fffafdee70846682067c180e0e10f7b095.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.slider.self-8911a7352cb577b6b7973b0734d57d2b624c79286558ffa36fcac0c29b2d0bee.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.tab.self-9bf6791513d1b20e213bb1aee3df0bc17128c7e18421258dc68a2a4ccabe1647.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.tooltip.self-834156796c253580629cfffc720bdc3d191b1e5a5a6ddbc1102ecd08c876516c.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation/foundation.topbar.self-105416f061562f07c6a0a8057d68282fdc1eeb5dc306713fcae6c9a53001fc55.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/foundation.self-abe4ee7a105042f73b12b1f1a28788522d2f253445a475a94ab4d6e1f7b0ec52.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/investor.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/assets/application.self-79a300d240bbf145c9af961805bc87f18e9f73bd1cda275895295c80d8552d3f.js?body=1" for ::1 at 2015-06-12 02:17:13 +0200


Started GET "/investors/new" for ::1 at 2015-06-12 02:17:16 +0200
Processing by InvestorsController#new as HTML
  Rendered shared/_error_messages.html.erb (4.2ms)
  Rendered investors/new.html.erb within layouts/application (20.6ms)
Completed 200 OK in 113ms (Views: 111.7ms | ActiveRecord: 0.0ms)


Started GET "/investors/new" for ::1 at 2015-06-12 02:18:04 +0200
Processing by InvestorsController#new as HTML
  Rendered shared/_error_messages.html.erb (0.0ms)
  Rendered investors/new.html.erb within layouts/application (2.7ms)
Completed 200 OK in 89ms (Views: 88.6ms | ActiveRecord: 0.0ms)


Started GET "/investors/new?utf8=%E2%9C%93&authenticity_token=qgXmHuloO7rKfYIUXFH5PVjsLDjpYcNDsX6gIff71a4n%2BEhe%2Fuu7DOt29%2B50S8B11TZp1uxaxf3%2BBqgSuHp%2B3Q%3D%3D&investor%5Bname%5D=Emmanuel&investor%5Bemail%5D=lalapnt%40yahoo.com&investor%5Bcountry%5D=Poland&investor%5Bphone%5D=000000000&commit=I%27m+interested%21" for ::1 at 2015-06-12 02:18:16 +0200
Processing by InvestorsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"qgXmHuloO7rKfYIUXFH5PVjsLDjpYcNDsX6gIff71a4n+Ehe/uu7DOt29+50S8B11TZp1uxaxf3+BqgSuHp+3Q==", "investor"=>{"name"=>"Emmanuel", "email"=>"[email protected]", "country"=>"Poland", "phone"=>"000000000"}, "commit"=>"I'm interested!"}
  Rendered shared/_error_messages.html.erb (1.1ms)
  Rendered investors/new.html.erb within layouts/application (7.9ms)
Completed 200 OK in 163ms (Views: 162.7ms | ActiveRecord: 0.0ms)
1

There are 1 answers

4
CDub On BEST ANSWER

The last part of your log file:

Started GET "/investors/new?utf8=%E2%9C%93&authenticity_token=qgXmHuloO7rKfYIUXFH5PVjsLDjpYcNDsX6gIff71a4n%2BEhe%2Fuu7DOt29%2B50S8B11TZp1uxaxf3%2BBqgSuHp%2B3Q%3D%3D&investor%5Bname%5D=Emmanuel&investor%5Bemail%5D=lalapnt%40yahoo.com&investor%5Bcountry%5D=Poland&investor%5Bphone%5D=000000000&commit=I%27m+interested%21" for ::1 at 2015-06-12 02:18:16 +0200
Processing by InvestorsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"qgXmHuloO7rKfYIUXFH5PVjsLDjpYcNDsX6gIff71a4n+Ehe/uu7DOt29+50S8B11TZp1uxaxf3+BqgSuHp+3Q==", "investor"=>{"name"=>"Emmanuel", "email"=>"[email protected]", "country"=>"Poland", "phone"=>"000000000"}, "commit"=>"I'm interested!"}
  Rendered shared/_error_messages.html.erb (1.1ms)
  Rendered investors/new.html.erb within layouts/application (7.9ms)
Completed 200 OK in 163ms (Views: 162.7ms | ActiveRecord: 0.0ms)

It looks like you're submitting a form to /investors/new but as a GET and not a POST, thus calling the #show action of /investors/new, rather than #create at /investors/new.

The raw HTML made me look closer - you have two form tags:

<form div class="small-6 large-centered columns">
    <fieldset>
        <legend> Enter your best details</legend>
<%= form_for(@investor) do |f| %>

Change this to:

<div class="small-6 large-centered columns">
    <fieldset>
        <legend> Enter your best details</legend>
<%= form_for(@investor) do |f| %>

In fact, your entire view will need to change:

<div class="small-6 large-centered columns">
  <%= form_for(@investor) do |f| %>
    <fieldset>
      <legend> Enter your best details</legend>

      <%= render 'shared/error_messages', object: f.object %>

      <%= f.label :name %>
      <%= f.text_field :name, :placeholder => "John Doe" %> </br>

      <%= f.label :email %>
      <%= f.text_field :email, :placeholder => "[email protected]" %></br>

      <%= f.label :country %>
      <%= f.text_field :country %></br>

      <%= f.label :phone %>
      <%= f.text_field :phone, :placeholder => "+48000000000" %></br>
    </fieldset>

    <%= f.submit "I'm interested!", :class => 'button radius' %>
  <% end %>
</div>