Code Monkey home page Code Monkey logo

members-only's Introduction

Members only

The motto of this assignment

  • To create basic authentication form (I use Devise gem)
  • If the user sign_in we have to display respective author name in the posts
  • Otherwise it will only display the posts without author name
  • without sign_in user cann't create post

Devise authentication

bundle add devise
rails generate devise:install
rails generate devise User
rails db:migrate

Post Controller, Model creation

rails generate controller Posts new create index --->[For this these 3 controller actions are enough]
rails geenrate model Post title:string content:text

Filter addition

I added a filter in the post controller this will prevent the user to create a post without sign_in

before_action :authenticate_user! only: [:new, :create]

Connection between post & user model

Right now there is no way of communication between both user and post models. To make we are adding a column(user_id) in the post model with reference to the user

rails generate migration AddUserIdToPosts user:references

post index logic

<h6>
  This is created by <%= User.find_by(id: post.user_id).email%>
  <%end%>
</h6>
Screencast.from.02-20-2024.07.38.51.PM.webm

members-only's People

Contributors

malavi1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.