0

I am working on an application where one controller controls the create action of several models. I have a lot more code, but I'm not sure if this error is specific to code or a generic fix (like changing the HTTP request) that doesn't require me to post my entire set up.

I have a 'basketball' model that belongs_to 'activities' that is generated from the activities controller. Each activity has_one basketball model.

Then in the basketballs controller I have this.

def edit
  @activity = Activity.find(params[:id])
  @basketball = @activity.basketball
 end

def update
  @activity = Activity.find(params[:id])
  @basketball = @activity.basketball
  if @basketball.update_attributes(basketball_params)
    flash[:notice] = "Activity has been updated."
    redirect_to activities_path
  else
    flash[:notice] = "Activity has not been updated."
    render 'edit'
  end

end

However, when I click the update button, my page renders a blank page with all of the parameters in the url. Example:

http://0.0.0.0:8080/basketballs/10/edit?utf8=%E2%9C%93&_method=patch&authenticity_token=[token]&basketball

Does anyone know how to fix this?

miler350
  • 1,411
  • 11
  • 15
  • It seems that the edit form method is `GET`. what do your logs look like? – Damien Sep 09 '13 at 18:05
  • Oh, I was using unicorn which isn't very descriptive. Webrick now says the request is too large. Request-URI Too Large WEBrick::HTTPStatus::RequestURITooLarge – miler350 Sep 09 '13 at 18:13
  • What does your form look like? – Damien Sep 09 '13 at 18:17
  • The form is huge. I'm going to try this: http://stackoverflow.com/questions/4926740/omniauth-google-openid-webrickhttpstatusrequesturitoolarge – miler350 Sep 09 '13 at 18:21
  • Ok, I used thin and now it says 'Bad Request.' The form is too large to post. I can create a gist, do you need the actual form or the params only? – miler350 Sep 09 '13 at 18:25
  • a gist is perfect. The actual form and the query please (using WEBrick for now) – Damien Sep 09 '13 at 19:13
  • The issue was/is GET request size. I counted the characters in the URL and it summed to 13,672. So I added this method: if defined?(WEBrick::HTTPRequest) WEBrick::HTTPRequest.const_set("MAX_URI_LENGTH", 20240) end to an initializer. that permits the string but no update yet. but no error. – miler350 Sep 09 '13 at 20:18
  • It doesn't explain why the params are displayed in the URL though. Still interested in the gists – Damien Sep 09 '13 at 20:32
  • https://gist.github.com/miler350/6501431 – miler350 Sep 09 '13 at 20:58
  • Let me know if you need anymore code. Thanks! – miler350 Sep 09 '13 at 21:09
  • Ouch, really massive indeed ;) But I didn't find anything wrong... May I see the log please? I want to check the form method, the params and the action called + any exceptions – Damien Sep 09 '13 at 21:44
  • https://gist.github.com/miler350/6501980 The log actually renders the edited params now btw. I increased the Webrick limit to 20,000. However, the create action doesn't work still and I don't think that's fix anyway because I don't use Webrick in production. – miler350 Sep 09 '13 at 21:48
  • Just to be clear: you want to update or create the resource? The only logs I saw were for the GET edit action. – Damien Sep 09 '13 at 21:54
  • I want to update the resource. – miler350 Sep 09 '13 at 22:02
  • Show me the **PUT/PATCH update** log. I only got the GET edit log please – Damien Sep 09 '13 at 22:05
  • How do you do that? Sorry for ignorance. – miler350 Sep 09 '13 at 22:07
  • Just clcik the submit button of your form and copy the output from the terminal. It should start with Started PATCH or something like that. – Damien Sep 09 '13 at 22:11
  • oh, like the line i posted in the original? https://gist.github.com/miler350/6502243#file-gistfile1-txt-L1 this is hard to read. – miler350 Sep 09 '13 at 22:16
  • This gist https://gist.github.com/miler350/6501980 is what you get when you try to **update** a resource? But it is a GET request to the edit action, not a,put/patch to the update action. I m confuse – Damien Sep 09 '13 at 22:23
  • https://gist.github.com/miler350/6502243#file-gistfile1-txt-L1 no this. this is the URL and my patch request. – miler350 Sep 09 '13 at 22:28
  • The update action is specified in your routes file? Post routes – Damien Sep 09 '13 at 22:29
  • The routes file doesn't have any magic. https://gist.github.com/miler350/6502392 – miler350 Sep 09 '13 at 22:32
  • Thats really weird. Do you have an open source version I can check? – Damien Sep 09 '13 at 22:37
  • https://github.com/miler350/corehero – miler350 Sep 09 '13 at 22:56
  • @miler350 These updates should be in your question, not in the comments. – George Stocker Sep 10 '13 at 12:05

1 Answers1

0

You have 3 nested forms in your views.

Here are the problems: app/views/strengthworkouts/_formatting.html.erb line 65 and app/views/workouts/_strengthworkout.html.erb line 5

Remove those <form> tags, keep the form_for.

Only the outermost form was used. And because it doesn't have any action or method or whatsoever attribute, submitting it just triggers a GET to the current path with the params in the query string.

Damien
  • 26,933
  • 7
  • 39
  • 40