0
votes

Am using rails 4 in my application with active admin gem. i wish to change my page default title when am rendering or redirecting to new or edit page , but the below code is not working.

my code is

form :title => { :new => "New action", :edit => "Edit action"} do |f|
   f.input reason, :label => "Reason", :input_html => {rows: 5} 
end

but when i use the below code its working

def new
      @page_title = "New Action"
    end
def edit
      @page_title = "Edit Action"
   end

but after validation rendering on new page its not updating the title ,because its only rendering not redirecting ,

def create
      @object = Model.new(params)

      respond_to do |format|
        if @object.save
          flash[:notice] = 'Saved Successfully'
          format.html { redirect_to collection_url }
        else
          format.html { render "new"  }
        end
      end
    end

how to solve this problem, can any one please help me

2
what is the aim? don't really understand. Please, add some info on how is it now, and how it should beAndrey Deineko

2 Answers

1
votes

Adding the @page_title in create and update method works .

after validation failed also that page title works when adding it into the create and update methods.

def create
      @page_title = "new  title"
       @object = Model.new(params)

      respond_to do |format|
        if @object.save
          flash[:notice] = 'Saved Successfully'
          format.html { redirect_to collection_url }
        else
          format.html { render "new"  }
        end
      end
    end
0
votes

Try this if its works, set

@page_title = "action_type"

where validation is getting failed i.e in else part. Rendering page will pick the new @page_title value