Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solo il #3

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions app/controllers/forecasts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
get '/forecasts' do
@forecasts = Forecasts.all
end


get '/forecasts/new' do
erb '/forecasts/new'
end


post '/forecasts' do
@forecast = Forecasts.new(params[:forecast])
if @forecast.save
redirect "forecasts"
else
@errors = @forecast.full_messages
erb '/forecasts/new'
end
end



get '/forecasts/:id' do
@forecast = Forecast.find(params[:id])
# @text_messages = @forecast.text_messages
erb :'forecasts/show'
end


#Edit
get '/forecasts/:id/edit' do
@forecast = Forecast.find(params[:id])
erb :'restaurants/edit'
end

put '/forecasts/:id' do
@forecast = Forecast.find(params[:id])
@forecast.update_attributes(params[:forecast])
if @forecast.save
redirect "/"
else
@errors = @restaurant.errors.full_messages
erb :'forecasts/edit'
end
end

#Delete
delete '/forecast/:id' do
@forecast = Forecast.find(params[:id])
@forecast.destroy
redirect '/'
end

2 changes: 1 addition & 1 deletion app/controllers/index.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
get '/' do
# @restaurants = Restaurant.all
@forecasts = Forecast.all
erb :'index'
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

delete '/sessions/:id' do
session[:id] = nil
redirect 'sessions/new'
redirect '/'
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

#update
def update_user
put '/users/:id' do
@user = User.find(params[:id])
@user.update(params[:user])
if @user.valid?
Expand All @@ -54,10 +54,6 @@ def update_user
# update_user
# end

put '/users/:id' do
update_user
end


#delete
delete '/users/:id' do
Expand Down
4 changes: 0 additions & 4 deletions app/models/follow.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/models/forecast.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Forecast < ActiveRecord::Base
belongs_to :user
end
6 changes: 1 addition & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
class User < ActiveRecord::Base
has_many :followers, through: :follower_follows, source: :follower
has_many :follower_follows, foreign_key: :followee_id, class_name: "Follow"

has_many :followees, through: :followee_follows, source: :followee
has_many :followee_follows, foreign_key: :follower_id, class_name: "Follow"
has_many :forecasts

validates :username, :email, :encrypted_password , presence:true
validates :email, uniqueness: true
Expand Down
2 changes: 1 addition & 1 deletion app/views/_errors.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul>
<ul class='errors'>
<% if @errors %>
<% @errors.each do |error| %>
<li><%= error %></li>
Expand Down
3 changes: 1 addition & 2 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<h1>Index page of the site</h1>

<a href= "/sessions/new">Login</a>
<a href='/users/new'>Register</a>

22 changes: 16 additions & 6 deletions app/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@
<div id="content">
<header>
<a href="/"><img src="/img/zenchinese.png" class="logo"></a>
<!-- <div id="login-toolbar">
<% if current_user %>
<a href="/logout">Logout</a>
<% else %>
<a href="/login">Login</a>
<% end %> -->

<div class='right'>
<%if !session[:id]%>
<a href="/sessions/new">login</a> |
<a href="/users/new">register</a>
<%else%>
<%=current_user.username%> |
<form method = "post" action = "/sessions/<%=session[:id]%>">
<input type= "hidden" name = "_method" value="delete">
<button type = "submit"> Log out </button>
</form>
<!-- <a href="/sessions/<%=session[:id]%>">logout</a> -->
<%end%>
</div>


</header>
<%= yield %>
</div>
Expand Down
4 changes: 0 additions & 4 deletions db/migrate/20141020120711_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ def change
t.string :username, null: false
t.string :email, null: false
t.string :encrypted_password, null: false
t.string :race
t.string :educational_attainment
t.string :marital_status
t.string :sex

t.timestamps
end
Expand Down
9 changes: 0 additions & 9 deletions db/migrate/20170424000652_create_follows.rb

This file was deleted.

14 changes: 14 additions & 0 deletions db/migrate/20170522202650_create_forecasts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateForecasts < ActiveRecord::Migration
def change
create_table :forecasts do |t|
t.string :location
t.datetime :date
t.string :temperature
t.string :wind
t.string :body

t.timestamps

end
end
end
54 changes: 52 additions & 2 deletions public/css/application.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
.right{
float: right;
margin-right: 5%;
text-decoration: none;
}

a:link {
text-decoration: none;
}

a:visited {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

a:active {
text-decoration: underline;
}

.errors{
color: red;
}

.container{
display: inline-block;
border: 1px solid black;
margin:4px;
padding:4px;
vertical-align: top;
height: 20vh;
}











/* CSS declarations go here */
body {font-family: Vollkorn; font-size: 160%; line-height: 160%; }
/*body {font-family: Vollkorn; font-size: 160%; line-height: 160%; }
h1, h2, h3, h4, h5, h6 {font-family: Georgia; line-height:100%; margin-top: 0.5em; margin-bottom: 0.5em; color: #36AECC; font-style: italic; font-weight: 400;}
h1 {font-size: 1.8em;}
h2 {font-size: 1.6em;}
Expand Down Expand Up @@ -64,4 +109,9 @@ code {
line-height: 1.4em;
margin-left: -1em;
overflow: auto;
}
}*/