Skip to content

Commit

Permalink
Merge pull request #3 from pawanghising67/newfunc
Browse files Browse the repository at this point in the history
Edit and update action
  • Loading branch information
pawanghising67 committed May 10, 2019
2 parents 06960c0 + 6cbbfb2 commit c964508
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 46 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/apartmentsws.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/apartmentsws.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the apartmentsws controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/apartmentsws_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ApartmentswsController < ApplicationController
before_action :set_apartmentsw, only: [:show, :edit, :update, :destroy]

# GET /apartmentsws
# GET /apartmentsws.json
def index
@apartmentsws = Apartmentsw.all
end

# GET /apartmentsws/1
# GET /apartmentsws/1.json
def show
end

# GET /apartmentsws/new
def new
@apartmentsw = Apartmentsw.new
end

# GET /apartmentsws/1/edit
def edit
end

# POST /apartmentsws
# POST /apartmentsws.json
def create
@apartmentsw = Apartmentsw.new(apartmentsw_params)

respond_to do |format|
if @apartmentsw.save
format.html { redirect_to @apartmentsw, notice: 'Apartmentsw was successfully created.' }
format.json { render :show, status: :created, location: @apartmentsw }
else
format.html { render :new }
format.json { render json: @apartmentsw.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /apartmentsws/1
# PATCH/PUT /apartmentsws/1.json
def update
respond_to do |format|
if @apartmentsw.update(apartmentsw_params)
format.html { redirect_to @apartmentsw, notice: 'Apartmentsw was successfully updated.' }
format.json { render :show, status: :ok, location: @apartmentsw }
else
format.html { render :edit }
format.json { render json: @apartmentsw.errors, status: :unprocessable_entity }
end
end
end

# DELETE /apartmentsws/1
# DELETE /apartmentsws/1.json
def destroy
@apartmentsw.destroy
respond_to do |format|
format.html { redirect_to apartmentsws_url, notice: 'Apartmentsw was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_apartmentsw
@apartmentsw = Apartmentsw.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def apartmentsw_params
params.require(:apartmentsw).permit(:title, :body, :user_id)
end
end
1 change: 1 addition & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class PostsController < ApplicationController

def homepage

end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/apartmentsws_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApartmentswsHelper
end
3 changes: 3 additions & 0 deletions app/models/apartmentsw.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Apartmentsw < ActiveRecord::Base
belongs_to :user
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

def username
return self.email.split('@')[0].capitalize
end
end


2 changes: 2 additions & 0 deletions app/views/apartmentsws/_apartmentsw.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! apartmentsw, :id, :title, :body, :, :user_id, :created_at, :updated_at
json.url apartmentsw_url(apartmentsw, format: :json)
30 changes: 30 additions & 0 deletions app/views/apartmentsws/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= form_for(@apartmentsw) do |f| %>
<% if @apartmentsw.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@apartmentsw.errors.count, "error") %> prohibited this apartmentsw from being saved:</h2>

<ul>
<% @apartmentsw.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %><br>
<%= f.text_field :body %>
</div>

<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/apartmentsws/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Apartmentsw</h1>

<%= render 'form' %>
<%= link_to 'Show', @apartmentsw %> |
<%= link_to 'Back', apartmentsws_path %>
File renamed without changes.
38 changes: 38 additions & 0 deletions app/views/apartmentsws/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<p id="notice"><%= notice %></p>

<h1>Listing Apartmentsws</h1>

<table>
<thead>
<tr>
<th>Title</th>
<th>Body</th>
<th></th>
<th>User</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @apartmentsws.each do |apartmentsw| %>
<tr>
<td><%= apartmentsw.title %></td>
<td><%= apartmentsw.body %></td>

<td><%= apartmentsw.user %></td>
<td><%= link_to 'Show', apartmentsw %></td>


<td><%= link_to 'Edit', edit_apartmentsw_path(apartmentsw) %></td>


<td><%= link_to 'Destroy', apartmentsw, method: :delete, data: { confirm: 'Are you sure?' } %></td>

</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Apartmentsw', new_apartmentsw_path %>
1 change: 1 addition & 0 deletions app/views/apartmentsws/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @apartmentsws, partial: 'apartmentsws/apartmentsw', as: :apartmentsw
5 changes: 5 additions & 0 deletions app/views/apartmentsws/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Apartmentsw</h1>

<%= render 'form' %>
<%= link_to 'Back', apartmentsws_path %>
21 changes: 21 additions & 0 deletions app/views/apartmentsws/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Title:</strong>
<%= @apartmentsw.title %>
</p>

<p>
<strong>Body:</strong>
<%= @apartmentsw.body %>
</p>



<p>
<strong>User:</strong>
<%= @apartmentsw.user%>
</p>

<%= link_to 'Edit', edit_apartmentsw_path(@apartmentsw) %> |
<%= link_to 'Back', apartmentsws_path %>
1 change: 1 addition & 0 deletions app/views/apartmentsws/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "apartmentsws/apartmentsw", apartmentsw: @apartmentsw
Empty file removed app/views/pages/Untitled
Empty file.
4 changes: 2 additions & 2 deletions app/views/pages/listfindapt.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<h1 class="jumbotron-heading">Xplor - Housing at MNSU</h1>
<p class="lead text-muted">We are here to give you a better living experience. Sign Up today and explore hundreds and thousands of options for your time at MNSU.</p>
<p>
<a href="https://xplor3-pawanghising67.c9users.io/posts/new" class="btn btn-primary my-2">List Apartment</a>
<a href="#" class="btn btn-secondary my-2">Find Apartment</a>
<a href="https://xplorrr-pawanghising67.c9users.io/apartmentsws/new" class="btn btn-primary my-2">List Apartment</a>
<a href="https://xplorrr-pawanghising67.c9users.io/apartmentsws" class="btn btn-secondary my-2">Find Apartment</a>

</p>
</div>
Expand Down
8 changes: 0 additions & 8 deletions app/views/posts/index.html.erb

This file was deleted.

22 changes: 0 additions & 22 deletions app/views/posts/new.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/posts/rental2.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/posts/show.html.erb

This file was deleted.

3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Rails.application.routes.draw do

resources :apartmentsws
devise_for :users
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'

end

root 'posts#homepage', as:'home'
root 'apartmentsws#homepage', as:'home'


get 'about' => 'pages#about', as: 'about'
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20190510140316_create_apartmentsws.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateApartmentsws < ActiveRecord::Migration
def change
create_table :apartmentsws do |t|
t.text :title
t.string :body

t.references :user, index: true, foreign_key: true

t.timestamps null: false
end
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190428181636) do
ActiveRecord::Schema.define(version: 20190510140316) do

create_table "apartmentsws", force: :cascade do |t|
t.text "title"
t.string "body"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "apartmentsws", ["user_id"], name: "index_apartmentsws_on_user_id"

create_table "posts", force: :cascade do |t|
t.string "title"
Expand Down

0 comments on commit c964508

Please sign in to comment.