0

I have a jobplacements model.When i create new jobplacement i am passing category as a param like this :

new_jobplacement_path(:category => params[:category])

so url looks like this :

http://localhost:3000/jobplacements/new?category=Corporate

but when validations fails url changes to :

http://localhost:3000/jobplacements

why this happens?where params category gets lost?how can i pass this params category when validations fail?

my create action code is :

def create
        @jobplacement = Jobplacement.new(params[:jobplacement])
        if @jobplacement.save
        redirect_to(jobplacement_url(@jobplacement.id,:category => @jobplacement.category), :notice => 'Job post was successfully created.') 
    else
        render :action => "new" 
    end
    end

2 Answers 2

0

This is because your route for create action is

PUT http://localhost:3000/jobplacements

When you validations fails, the page is not redirected, so the url is remained.

Anyway, this will not cause problems.

2
  • no this causes problem because i need to store category through params...and when validations fails since there is no params value category is stored as empty which i dont want..
    – NJF
    Jun 1, 2012 at 5:25
  • @NJF So you need to change your create route, let it have category.
    – xdazz
    Jun 1, 2012 at 5:29
0

solved it... added :url => { :action => :create, :category => params[:category]} in form.html.haml:

= form_for(@jobplacement,:url => { :action => :create, :category => params[:category]},:validate => true, :html => { :class => "form grid_6", :id => "form" }) do |f|

now when validations fail my url changes to :

http://localhost:3000/jobplacements?category=Corporate

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.