1

I need to modify the issue's start_date and due_date some how,

But I haven't used Rails before, so I don't know how the it run in server, And I need to implement it in a short time.

So I add these code in the controller,

  def date
    issue = Issue.find(params[:id])
    issue.start_date = params[:start_date]
    issue.due_date = params[:due_date]
    ntc_str = "Fail to save!" + params[:id]
    if issue.save
       ntc_str = 'Issue saved!'
    end
    flash[:notice] = ntc_str;
    redirect_to :controller => 'gantts', :action => 'show', :project_id => params[:p_id]
  end

It runs when I access it by myself It always failed and the "ntc_str" always is "Fail to save!" if I use javascript to access it.

For example: It runs when I input the url "http://xxx.xxx.xxx.xxx/date?id=6&project_id=test&start_date=2016-06-08&due_date=2016-06-30" by hands, But it failed when I use javascript "window.location.href='/date?id=6&project_id=test&start_date=2016-06-08&due_date=2016-06-30'"

It runs when I input the params in the form I create and click to submit it, But it failed when I use javascript "document.getElementById('start_date').value = '2016-06-30'; /..../ $('#test-form').submit()"

Could you tell me why it always fails and how can I use the issue model? I have be crazy now.

BabyCabbage
  • 187
  • 1
  • 9

1 Answers1

0

It would be useful, if you provide some logs with each cases you try.

Also, you can see what goes wrong with issue, when you try to save it, with:

if issue.save
   ntc_str = 'Issue saved!'
else 
   Rails.logger.error(issue.errors.full_messages)
end
olmstad
  • 686
  • 5
  • 9