dhampik / rails-admin-scaffold

Rails generator which allows to scaffold admin controllers, views with proper (non-namespaced) models, helpers, tests and routes
MIT License
92 stars 37 forks source link

respond_with rather than respond_to #9

Closed joshuapaling closed 10 years ago

joshuapaling commented 10 years ago

Are you interested in using the more concise respond_with rather than respond_to?

An example of each:

This is code generated using the rails-admin-scaffold gem:

  # POST /admin/programs
  def create
    @program = Program.new(program_params)

    respond_to do |format|
      if @program.save
        format.html { redirect_to admin_programs_path, notice: 'Program was successfully created.' }
      else
        format.html { render action: 'new' }
      end
    end
  end

  # PATCH/PUT /admin/programs/1
  def update
    respond_to do |format|
      if @program.update(program_params)
        format.html { redirect_to admin_programs_path, notice: 'Program was successfully updated.' }
      else
        format.html { render action: 'edit' }
      end
    end
  end

  # DELETE /admin/programs/1
  def destroy
    @program.destroy
    respond_to do |format|
      format.html { redirect_to admin_programs_url, notice: 'Program was successfully destroyed.' }
    end
  end

And this is code generated by the default rails generators:

  def create
    @workout = Workout.new(workout_params)
    @workout.save
    respond_with(@workout)
  end

  def update
    @workout.update(workout_params)
    respond_with(@workout)
  end

  def destroy
    @workout.destroy
    respond_with(@workout)
  end

If you're interested in using respond_with I'll try find the time to submit a PR.

joshuapaling commented 10 years ago

I'd be in favour of making minimal controllers, as rails generators currently do, and for users who want flash messages, recommend using https://github.com/plataformatec/responders, rather than maintaining flash messages in this gem.

What do you think?

joshuapaling commented 10 years ago

Ah - I've realised that rails has both a scaffold_controller and a responders_controller, so I guess this gem intentionally implements the first one - and in this issue I've been referring to the second.