Hotwired wi[
This commit is contained in:
20
app/controllers/hello_controller.rb
Normal file
20
app/controllers/hello_controller.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class HelloController < ApplicationController
|
||||
before_action only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@employers = Employer.all
|
||||
@employer = Employer.new
|
||||
end
|
||||
|
||||
# def create
|
||||
# @product.increment! :retweets_count
|
||||
# redirect_to @tweet
|
||||
# end
|
||||
|
||||
private
|
||||
|
||||
# def set_tweet
|
||||
# # @tweet = Tweet.find(params[:tweet_id])
|
||||
# end
|
||||
end
|
||||
|
||||
10
app/javascript/controllers/application.js
Normal file
10
app/javascript/controllers/application.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Application } from "@hotwired/stimulus"
|
||||
|
||||
const application = Application.start()
|
||||
|
||||
// Configure Stimulus development experience
|
||||
application.warnings = true
|
||||
application.debug = false
|
||||
window.Stimulus = application
|
||||
|
||||
export { application }
|
||||
7
app/javascript/controllers/hello_controller.js
Normal file
7
app/javascript/controllers/hello_controller.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.element.textContent = "Hello World!"
|
||||
}
|
||||
}
|
||||
7
app/javascript/controllers/index.js
Normal file
7
app/javascript/controllers/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// This file is auto-generated by ./bin/rails stimulus:manifest:update
|
||||
// Run that command whenever you add a new controller
|
||||
|
||||
import { application } from "./application"
|
||||
|
||||
import HelloController from "./hello_controller"
|
||||
application.register("hello", HelloController)
|
||||
@@ -5,9 +5,13 @@
|
||||
//
|
||||
import Rails from "@rails/ujs"
|
||||
import Turbolinks from "turbolinks"
|
||||
import { Turbo } from "@hotwired/turbo-rails"
|
||||
import * as ActiveStorage from "@rails/activestorage"
|
||||
import "controllers"
|
||||
import "channels"
|
||||
|
||||
Rails.start()
|
||||
Turbolinks.start()
|
||||
window.Turbo = Turbo
|
||||
Turbo.start()
|
||||
ActiveStorage.start()
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
class Employer < ApplicationRecord
|
||||
after_create_commit { broadcast_prepend_to "employers" }
|
||||
after_update_commit { broadcast_replace_to "employers" }
|
||||
after_destroy_commit { broadcast_remove_to "employers" }
|
||||
|
||||
include Recentable
|
||||
|
||||
has_many :subscriptions
|
||||
|
||||
7
app/views/employers/_employer.html.erb
Normal file
7
app/views/employers/_employer.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<%= turbo_frame_tag dom_id(employer) do %>
|
||||
<div class="card card-body">
|
||||
<div>Something </div>
|
||||
<div><%= employer.name %></div>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
2
app/views/employers/_employer.json.jbuilder
Normal file
2
app/views/employers/_employer.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! employer, :id, :name
|
||||
|
||||
5
app/views/hello/_employer.html.erb
Normal file
5
app/views/hello/_employer.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= turbo_frame_tag dom_id(employer) do %>
|
||||
<div class="card card-body">
|
||||
<div><%= @employer.name %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
2
app/views/hello/_employer.json.jbuilder
Normal file
2
app/views/hello/_employer.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! employer, :id, :name
|
||||
|
||||
23
app/views/hello/_form.html.erb
Normal file
23
app/views/hello/_form.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<%= form_with(model: employer, id: dom_id(employer)) do |form| %>
|
||||
<% if employer.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(employer.errors.count, "error") %> prohibited this employer from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% tweet.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :name %>
|
||||
<%= form.text_area :name %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
243
app/views/hello/index.html.erb
Normal file
243
app/views/hello/index.html.erb
Normal file
File diff suppressed because one or more lines are too long
1
app/views/hello/index.json.jbuilder
Normal file
1
app/views/hello/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @employers, partial: "tweets/tweet", as: :employer
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
<%= bootstrap_form_with model: model, local: true do |form| %>
|
||||
V <%= form.text_field :name %>
|
||||
<%= form.text_field :name %>
|
||||
<%= form.time_zone_select(:shoot_location_time_zone, nil, label: "Time zone of shoot location") %> <div class="row align-items-center text-center mt-4">
|
||||
<%= link_to t("shared.cancel"), [project, :broadcasts], class: "col-3 text-reset" %>
|
||||
<div class="col-9">
|
||||
|
||||
Reference in New Issue
Block a user