Skip to content

Conversation

@justin808
Copy link
Member

@justin808 justin808 commented Oct 4, 2025

Summary

  • Fixed rails new command failing with "can't find executable rails for gem railties" error
  • Escaped bundle context by prefixing command with BUNDLE_GEMFILE=

Problem

The bin/new-demo script was failing when trying to create a new Rails app because:

  1. The script uses require 'bundler/setup' to load dependencies
  2. This causes Bundler to intercept the rails command
  3. Bundler tries to find railties in the current bundle (which doesn't have it)
  4. Command fails with gem not found error

Solution

Prefix the rails new command with BUNDLE_GEMFILE= to temporarily escape the bundle context and use the globally installed Rails gem instead.

Test plan

  • Run bin/new-demo with the fix applied
  • Verify Rails app is created successfully
  • RuboCop passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improves reliability when creating demo Rails apps by running the generator with a clean Bundler context, avoiding unintended use of an existing Gemfile.
    • Reduces setup errors and unexpected dependency resolutions in environments where BUNDLE_GEMFILE or a local Gemfile might interfere.

@coderabbitai
Copy link

coderabbitai bot commented Oct 4, 2025

Warning

Rate limit exceeded

@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f8c75b8 and 912ab10.

📒 Files selected for processing (5)
  • .new-demo-versions (1 hunks)
  • bin/new-demo (1 hunks)
  • bin/scaffold-demo (1 hunks)
  • lib/demo_scripts/config.rb (2 hunks)
  • lib/demo_scripts/demo_creator.rb (2 hunks)

Walkthrough

The Rails app creation command in lib/demo_scripts/demo_creator.rb now prefixes the execution with an empty BUNDLE_GEMFILE environment variable. No other logic or public interfaces were changed.

Changes

Cohort / File(s) Summary
Rails app creation command
lib/demo_scripts/demo_creator.rb
Updated create_rails_app to run Rails with an empty BUNDLE_GEMFILE by prefixing the command: BUNDLE_GEMFILE= rails new .... No other changes.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant DC as DemoCreator
    participant Run as Runner
    participant Sh as Shell

    Dev->>DC: create_rails_app(args)
    DC->>Run: run!("BUNDLE_GEMFILE= rails new '<demo_dir>' <args>")
    note right of Run: Environment variable BUNDLE_GEMFILE set to empty
    Run->>Sh: Execute command
    Sh-->>Run: Exit status / output
    Run-->>DC: Result
    DC-->>Dev: Completion
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I set my gems aside—just for a spell,
Hop—rails new!—with a clean config shell.
No bundle path to wander or roam,
Fresh tracks in sand, a scaffolded home.
Thump-thump! says the dev-bun, bright—
A tidy start, crisp as morning light.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title directly references the fix applied to the rails new command within a Bundler context and aligns with the PR’s core objective of escaping the current bundle by prefixing BUNDLE_GEMFILE=. It is concise, specific, and clearly conveys the primary change to reviewers.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

justin808 and others added 2 commits October 3, 2025 23:00
The rails new command was failing with "can't find executable rails for gem railties"
because it was running within the script's Bundler context. This happened because
bin/new-demo requires 'bundler/setup', causing Bundler to intercept the rails command
and look for railties in the current bundle.

Fixed by prefixing the command with BUNDLE_GEMFILE= to escape the bundle context and
use the globally installed Rails gem.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The previous fix using BUNDLE_GEMFILE= didn't work because the rails
executable wrapper script calls Gem.use_gemdeps which still loads the
Gemfile dependencies.

Changed approach to use Rails version specifier (rails _8.0.3_ new) which
bypasses the bundle context and uses the specified gem version directly.

Changes:
- Added RAILS_VERSION configuration to Config class and .new-demo-versions
- Updated DemoCreator to use rails _VERSION_ new syntax
- Added Rails version display in output
- Fixed RuboCop style violations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@justin808
Copy link
Member Author

@claude review this pr

@claude
Copy link

claude bot commented Oct 4, 2025

Claude finished @justin808's task —— View job


PR Review: Fix rails new command failing in bundle context

Summary

This PR addresses a bundle context issue when creating new Rails apps, but the actual fix is different from what the PR description claims. The description says the fix is to prefix the command with BUNDLE_GEMFILE=, but that's not what the code changes show.


✅ What Actually Changed

lib/demo_scripts/demo_creator.rb:76

# Before:
@runner.run!("bundle exec rails new '#{@demo_dir}' #{all_args}")

# After:
@runner.run!("rails _#{@config.rails_version}_ new '#{@demo_dir}' #{all_args}")

The actual fix is:

  1. Removed bundle exec - This stops Bundler from intercepting the command
  2. Added explicit Rails version _#{@config.rails_version}_ - This tells RubyGems to use the specific Rails version installed globally

This is a different approach than using BUNDLE_GEMFILE= and is actually a better solution.


📋 Review Findings

✅ Strengths

  1. Correct Solution: Using rails _VERSION_ is the standard way to run a specific Rails version and automatically escapes bundle context
  2. Version Consistency: Added RAILS_VERSION configuration support throughout:
    • Added to .new-demo-versions config file
    • Added to Config class with proper loading/fallback logic
    • Added user-facing output showing which Rails version is being used
  3. Code Quality:
    • Changed if/elsif to case/when in config.rb:27-34 (cleaner pattern matching)
    • Added helpful user feedback: "Using Rails 8.0.3"
  4. Minor Improvements: Fixed line-length formatting in bin files

⚠️ Issues to Address

1. PR Description Mismatch (Critical)

  • The PR description claims the fix is BUNDLE_GEMFILE= rails new ...
  • The actual implementation is rails _8.0.3_ new ...
  • Action needed: Update PR description to accurately reflect the implemented solution

2. Missing Change Documentation
The PR description focuses only on the bundle context fix but doesn't mention:

  • Addition of RAILS_VERSION configuration support
  • Migration from bundle exec rails to explicit version syntax
  • Refactoring of config loading logic

3. Test Coverage

  • PR mentions "Test plan: Run bin/new-demo" was completed ✅
  • But doesn't verify the version override works: bin/new-demo test --rails-version 7.2.0

🔍 Technical Analysis

Why This Fix Works:

The original code used bundle exec rails new, which:

  1. Makes Bundler look for rails in the current bundle's context
  2. Fails because the parent script's bundle (loaded via require 'bundler/setup') doesn't include railties

The new code uses rails _8.0.3_ new, which:

  1. Bypasses Bundler entirely by calling the globally installed gem directly
  2. Uses RubyGems' version specification syntax to target a specific Rails version
  3. Works even when require 'bundler/setup' has modified the load path

Alternative Approaches:

  • BUNDLE_GEMFILE= rails new (mentioned in PR description) - Would also work
  • Bundler.with_unbundled_env { ... } - Ruby API approach
  • Current solution is simpler and more explicit

📝 Recommendations

  1. Update PR description to match the actual implementation
  2. Consider documenting why rails _VERSION_ was chosen over BUNDLE_GEMFILE=
  3. Add test for custom Rails version override to ensure the new parameter works
  4. Optional: Add validation that the specified Rails version is actually installed

✅ Approval Status

Despite the documentation mismatch, the code changes are sound and solve the problem correctly. The implementation is actually cleaner than what was described. Once the PR description is updated to match reality, this is ready to merge.

Code changes: Approved ✅
Documentation: Needs update ⚠️


Job Run | Branch: test-installer

@justin808 justin808 merged commit fe14b75 into main Oct 4, 2025
2 checks passed
@justin808 justin808 deleted the test-installer branch October 4, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants