Skip to content

Instantly share code, notes, and snippets.

@shanebarringer
Created November 2, 2016 12:48
Show Gist options
  • Save shanebarringer/72897a7460119da8c05a7e6a3c3e8049 to your computer and use it in GitHub Desktop.
Save shanebarringer/72897a7460119da8c05a7e6a3c3e8049 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :authenticate_user!
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :username, :bio, :location, :email, :password, :password_confirmation])
devise_parameter_sanitizer.permit(:account_update, keys: [:name, :username, :bio, :location, :email, :password, :password_confirmation])
end
end
<h1>New Tweet</h1>
<%= form_for(@tweet) do |f| %>
<% if @tweet.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tweet.errors.count, "error") %> prohibited this tweet from being saved:</h2>
<ul>
<% @tweet.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :message %><br>
<%= f.text_field :message %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id, value: current_user.id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<%= link_to 'Back', tweets_path %>
Rails.application.routes.draw do
resources :tweets
root 'tweets#index'
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
class TweetsController < ApplicationController
def index
end
def new
@tweet = Tweet.new
end
def create
@tweet = Tweet.new(tweet_params)
respond_to do |format|
if @tweet.save
format.html { redirect_to tweet_path(@tweet.id), notice: 'success!'}
else
format.html { render :new, error: 'there was a problem' }
end
end
end
def edit
end
def show
end
private
def tweet_params
params.require(:tweet).permit(:message, :user_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment