3

I have the following code in my controller

  def create
    @severity = Severity.new(params[:severity])
    if @severity.save
      flash[:notice] = "Successfully created severity"
      render 'save'
    end
  end

I am trying to get the method to render another view file other than create.js.erb however the controller always renders the default rather than the save.js.erb.

Any ideas on what could be wrong?

1 Answer 1

3
def create
  @severity = Severity.new(params[:severity])
  if @severity.save
    flash[:notice] = "Successfully created severity"
    respond_to do |format|
      format.js { render :template => "/path/to/save" }
    end
  end
end

or

def create
  @severity = Severity.new(params[:severity])
  if @severity.save
    flash[:notice] = "Successfully created severity"
    respond_to do |format|
      format.js { render :file => "/path/to/save.js.erb" }
    end
  end
end

try this

def create
  @severity = Severity.new(params[:severity])
  if @severity.save
    flash[:notice] = "Successfully created severity"
  end
  render :file => "/path/to/save.js.erb"
end
Sign up to request clarification or add additional context in comments.

5 Comments

this did not work, I added the render template version of the code pointing to severities/save and it still rendered the default create.js.erb file. Do I need to include the full path?
how do you cal this action? through ajax?
Yes I have a form_for with the :remote => true attribute
Still no luck, despite which method I use to try and render another view it always defaults to rendering create.js.erb
and if you'll try this: render :text => "Hello world!" if it won't return hello world then your problem is not about you think

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.