Code Monkey home page Code Monkey logo

Comments (2)

JoeDupuis avatar JoeDupuis commented on May 26, 2024 3

@yshmarov, I've suggested this before, but ended up not writing the PR, because someone on Rails core (I believe DHH), mentioned that the scaffold are intentionally "ugly" or bare. They are not intended to be used as is. You are expected to modify them heavily.

In practice, I found that a lot of those modifications where very repetitive, so I wrote a set of generators to handle it for me.

I think that there is a case to be made for upstreaming something like this. Although, it would likely be an an uphill battle.

I rely a lot less on scaffolds than I use to, but I think there is good reasons to use the I18n layer even without translating the app. It let you separate copy from the code.

Take this controller action for example:

def update
    if @book.update(book_params)
      redirect_to @book, notice: success_message(@book)
    else
      render :edit, status: :unprocessable_entity
    end
end

and the helper implementation:

  def success_message model = nil
    args = {}
    args[:name] = model.model_name.human if model
    t(".success", default: :"application.#{action_name}.success", **args)
  end

This lets me

  • have a generic success message that adapts automatically to the model name.
  • I can change the model name showed to the user independently from how it is called in the code.
  • I can write custom success message per model if needed.
  • The controller doesn't have to worry about copy. It is only focused on returning a success message. It doesn't have to care what the success message is.

I'll try to post my generators soonβ„’ and I'll open the discussion again.

from rails.

skipkayhil avatar skipkayhil commented on May 26, 2024

Thank you for the suggestion but we reserve the issue tracker for bugs only. For feature requests/discussion the best place would be the forums

from rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.