Project

General

Profile

[HELP] How to save data using Redmine issue model

Added by WC W almost 8 years ago

Hi all, 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.


Replies (3)

RE: [HELP] How to save data using Redmine issue model - Added by Martin Denizet (redmine.org team member) almost 8 years ago

Hello,

Try to modify such as:

ntc_str = issue.errors.messages

It should give you the list of errors allowing you to understand what is going on.

You can also try to replace issue.save by issue.save! for exceptions not to be caught (Check logs).

Cheers,

RE: [HELP] How to save data using Redmine issue model - Added by WC W almost 8 years ago

Thanks for your reply

I broke the database by accident and re-build it today

And the problem disappeared!

Although I still don't know why.

RE: [HELP] How to save data using Redmine issue model - Added by WC W almost 8 years ago

Martin Denizet (redmine.org team member) wrote:

Hello,

Try to modify such as:

ntc_str = issue.errors.messages

It should give you the list of errors allowing you to understand what is going on.

You can also try to replace issue.save by issue.save! for exceptions not to be caught (Check logs).

Cheers,

And another problem occurred:

Started GET "/projects/test-project/issues/gantt" for 172.26.142.125 at 2016-06-16 12:55:09 +0800
Processing by GanttsController#show as HTML
Parameters: {"project_id"=>"test-project"}
Current user: admin (id=1)
Rendered queries/_filters.html.erb (8.5ms)
Rendered issues/_sidebar.html.erb (8.1ms)
Rendered gantts/show.html.erb within layouts/base (275.6ms)
Completed 500 Internal Server Error in 391ms (ActiveRecord: 108.6ms)

ActionView::Template::Error (undefined method `html_safe' for #<Hash:0x007f74488ddad8>):
97: <div id="sidebar">
98: <%= yield :sidebar >
99: <
= view_layouts_base_sidebar_hook_response >
100: </div>
101:
102: <div id="content">
103: <
= render_flash_messages %>
app/helpers/application_helper.rb:312:in `block in render_flash_messages'
app/helpers/application_helper.rb:311:in `render_flash_messages'
app/views/layouts/base.html.erb:100:in `_app_views_layouts_base_html_erb__3347342889153165068_68694940'
app/controllers/gantts_controller.rb:43:in `block (2 levels) in show'
app/controllers/gantts_controller.rb:42:in `show'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

Could you tell me what it means?

    (1-3/3)