Ryan Mindigo

Joined

920 Experience
1 Lesson Completed
1 Question Solved

Activity

Posted in Multitenancy with the Apartment gem Discussion

+1 to this

Posted in How do I migrate apartment gem to Heroku correctly?

will check it out thanks!

Posted in How do I migrate apartment gem to Heroku correctly?

I am getting same issue.

Posted in Group Chat with ActionCable: Part 5 Discussion

@chris, I just finished video #5 of the Chatrooms tutorial. Everything looks ok in terminal output, but when I hit 'enter' key after typing a message I still have to refresh browser to see the message appear. Here is repo: https://github.com/rmindigo/chat_demo_gorails Any ideas why message doesn't appear instantly? Terminal output below. Thanks!

[ActionCable] [User 12] Finished "/cable/" [WebSocket] for 127.0.0.1 at 2019-01-29 16:51:10 -0800
[ActionCable] [User 12] ChatroomsChannel stopped streaming from chatrooms:3
Started GET "/cable" for 127.0.0.1 at 2019-01-29 16:51:10 -0800
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-01-29 16:51:10 -0800
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 12], ["LIMIT", 1]]
[ActionCable] [User 12] Registered connection (Z2lkOi8vY2hhdC9Vc2VyLzEy)
[ActionCable] [User 12] Chatroom Load (0.3ms) SELECT "chatrooms".* FROM "chatrooms" INNER JOIN "chatroom_users" ON "chatrooms"."id" = "chatroom_users"."chatroom_id" WHERE "chatroom_users"."user_id" = ? [["user_id", 12]]
[ActionCable] [User 12] ChatroomsChannel is transmitting the subscription confirmation
[ActionCable] [User 12] ChatroomsChannel is streaming from chatrooms:3
[ActionCable] [User 12] ChatroomsChannel#send_message({"chatroom_id"=>3, "body"=>"see my message"})
[ActionCable] [User 12] Chatroom Load (0.3ms) SELECT "chatrooms".* FROM "chatrooms" WHERE "chatrooms"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
[ActionCable] [User 12] (0.1ms) begin transaction
[ActionCable] [User 12] SQL (0.8ms) INSERT INTO "messages" ("chatroom_id", "user_id", "body", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["chatroom_id", 3], ["user_id", 12], ["body", "see my message"], ["created_at", "2019-01-30 00:51:22.264530"], ["updated_at", "2019-01-30 00:51:22.264530"]]
[ActionCable] [User 12] (28.0ms) commit transaction
Message Load (0.4ms) SELECT "messages".* FROM "messages" WHERE "messages"."id" = ? LIMIT ? [["id", 49], ["LIMIT", 1]]
[ActionCable] [User 12] [ActiveJob] Enqueued MessageRelayJob (Job ID: b63d1b75-902b-47c9-b864-d6aec9495db6) to Async(default) with arguments: #<GlobalID:0x007f90e113e998 @uri=#<URI::GID gid://chat/Message/49>>
[ActiveJob] [MessageRelayJob] [b63d1b75-902b-47c9-b864-d6aec9495db6] Performing MessageRelayJob (Job ID: b63d1b75-902b-47c9-b864-d6aec9495db6) from Async(default) with arguments: #<GlobalID:0x007f90e1137f08 @uri=#<URI::GID gid://chat/Message/49>>
[ActiveJob] [MessageRelayJob] [b63d1b75-902b-47c9-b864-d6aec9495db6] Chatroom Load (0.2ms) SELECT "chatrooms".* FROM "chatrooms" WHERE "chatrooms"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
[ActiveJob] [MessageRelayJob] [b63d1b75-902b-47c9-b864-d6aec9495db6] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 12], ["LIMIT", 1]]
[ActiveJob] [MessageRelayJob] [b63d1b75-902b-47c9-b864-d6aec9495db6] [ActionCable] Broadcasting to chatrooms:3: {:username=>"bratPitt", :body=>"see my message", :chatroom_id=>3}
[ActiveJob] [MessageRelayJob] [b63d1b75-902b-47c9-b864-d6aec9495db6] Performed MessageRelayJob (Job ID: b63d1b75-902b-47c9-b864-d6aec9495db6) from Async(default) in 3.17ms
[ActionCable] [User 12] ChatroomsChannel transmitting {"username"=>"bratPitt", "body"=>"see my message", "chatroom_id"=>3} (via streamed from chatrooms:3)

Posted in Group Chat with ActionCable: Part 4 Discussion

Same error for me. Will just press on and hope things work when we addd ActionCable.

got the answer, needed to add one line to the new action in AccountsController

@account.users.build

Posted in How do I remove associated records?

have you tried this? or some variation of dependent: :destroy on the model associations

has_many :students, through: :attendances, source: :student, dependent: :destroy

https://guides.rubyonrails.org/association_basics.html

Posted in How update value which run from strong params??

Hello! I am building an app with Accounts/Users & Memberships via has_many through. I am using Devise and want to create a new user from 'accounts#new" via 'accepts_nested_attributes_for.'

When I fill out the form to create a new Account & User, the Account is being created, but no User. I am seeing 'unpermitted parameter: :user.'

I assume there is something missing in my Controller. Here is the terminal output and code below.

I am able to successfully create a new Account and User in console

 hey.memberships
  Membership Load (0.4ms)  SELECT  "memberships".* FROM "memberships" WHERE "memberships"."user_id" = ? LIMIT ?  [["user_id", 3], ["LIMIT", 11]]
 => #<ActiveRecord::Associations::CollectionProxy [#<Membership id: 1, user_id: 3, account_id: 6, created_at: "2018-12-30 20:43:07", updated_at: "2018-12-30 20:43:07">]> 

Any help would be greatly appreciated!

Parameters: {"utf8"=>"✓", "authenticity_token"=>"6eMcKYXDsP/XX+LyvCY2/yxnyWThWT3Upjc9WDAEF828iJ4Afdk3Z5X0DP8PKGJSVBR+MM6OxyITx9aFMM9MCw==", "account"=>{"name"=>"chesterfield", "user"=>{"email"=>"jason@aol.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}, "commit"=>"Create Account"}
Unpermitted parameter: :user
   (0.1ms)  begin transaction
  SQL (0.5ms)  INSERT INTO "accounts" ("name", "created_at", "updated_at") VALUES (?, ?, ?)  [["name", "chesterfield"], ["created_at", "2019-01-01 17:15:55.817878"], ["updated_at", "2019-01-01 17:15:55.817878"]]
   (41.4ms)  commit transaction
Redirected to http://localhost:3000/accounts/12
Completed 302 Found in 46ms (ActiveRecord: 42.1ms)

AccountsController

 def new
    @account = Account.new
  end

     def create
    @account = Account.new(account_params)
    respond_to do |format|
      if @account.save
        format.html { redirect_to @account, notice: 'Account was successfully created.' }
        format.json { render :show, status: :created, location: @account }
      else
        format.html { render :new }
        format.json { render json: @account.errors, status: :unprocessable_entity }
      end
    end
  end

    def account_params
      params.require(:account).permit(:name, users_attributes: [:email, :password, :password_confirmation])
    end

Account Form

<%= form_with(model: account, local: true) do |form| %>
  <% if account.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(account.errors.count, "error") %> prohibited this account from being saved:</h2>

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

  <div class="field">
    <%= form.label :name %>
    <%= form.text_field :name, id: :account_name %>
  </div>

  <div class="field">
    <%= form.fields_for :user do |f| %>
          <div class="field">
            <%= f.label :email %><br />
            <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
          </div>

          <div class="field">
            <%= f.label :password %>
            <% if @minimum_password_length %>
            <em>(<%= @minimum_password_length %> characters minimum)</em>
            <% end %><br />
            <%= f.password_field :password, autocomplete: "new-password" %>
          </div>

          <div class="field">
            <%= f.label :password_confirmation %><br />
            <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
          </div>
    <% end %>      
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

Models

class Account < ApplicationRecord
    has_many :memberships
    has_many :users, through: :memberships
    accepts_nested_attributes_for :users
end

class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  has_many :memberships
  has_many :accounts, through: :memberships     
end

class Membership < ApplicationRecord
  belongs_to :user, optional: true
  belongs_to :account, optional: true
end

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.