Forum: Ruby on Rails create action, fails validation, renders new and then calls the index action silent the background?

0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2013-11-08 18:43
(Received via mailing list)
Hi Guys,

Strange issue going on, cant get to the bottom of it.

I have a bog standard form which submits to the create action fine.  If
the
validation fails however the new action is rendered with the appropriate
errors,
however in the logs i notice the index action is called silently and I
can
see the trace of sql, see below:

controller code

def create
    @discussion = Discussion.new
    @discussion.assign_attributes(params[:discussion].merge(created_by_id:
current_user.id), :as => :admin)
    respond_to do |format|
      if @discussion.save
        format.html { redirect_to discussion_path(@discussion), notice:
"Discussion was successfully created."}
      else
        format.html { render 'new' }
      end
    end
  end

Started POST "/discussions" for 127.0.0.1 at 2013-11-08 17:35:29 +0000
Processing by DiscussionsController#create as HTML
  Parameters: {"utf8"=>"✓",
"authenticity_token"=>"Xmxr58tjF1TEUUWFL+u3/VNzl/1HM83kAeD60LieP/0=",
"discussion"=>{"title"=>"", "body"=>"", "user_ids"=>[""]},
"commit"=>"submit"}
 [1m [36m (2.3ms) [0m   [1mBEGIN [0m
  [1m [35m (2.2ms) [0m  ROLLBACK
blah blah.....
Rendered discussions/new.html.erb within layouts/launchpad (50.5ms)
Completed 200 OK in 362.0ms (Views: 274.6ms | ActiveRecord: 78.1ms)

Started GET "/discussions" for 127.0.0.1 at 2013-11-08 17:35:30 +0000
Processing by DiscussionsController#index as HTML
   [1m [36mUser Load (3.4ms) [0m   [1mSELECT "users".* FROM "users"
WHERE
"users"."id" = 8 LIMIT 1 [0m
   [1m [35mContext Load (2.4ms) [0m  SELECT "contexts".* FROM "contexts"
WHERE "contexts"."id" = $1 LIMIT 1  [["id", "2"]]
   [1m [36mRole Load (4.3ms) [0m   [1mSELECT "roles".* FROM "roles"
WHERE
"roles"."name" = 'PC_USER' LIMIT 1 [0m
   [1m [35mRole Load (3.8ms) [0m  SELECT "roles".* FROM "roles"
  Rendered admin/shared/_quick_links.html.erb (2.1ms)
   [1m [36mDiscussion Load (3.6ms) [0m   [1mSELECT DISTINCT
discussions.*
FROM "discussions" INNER JOIN "discussions_users" ON
"discussions_users"."discussion_id" = "discussions"."id" INNER JOIN
"users"
ON "users"."id" = "discussions_users"."user_id" WHERE (created_by_id = 8
OR
discussions_users.user_id = 8 OR users.account_id = 1) [0m
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2013-11-09 23:55
(Received via mailing list)
On Nov 8, 2013, at 11:41 AM, johnnybutler7 <johnnybutler7@gmail.com>
wrote:

>     @discussion = Discussion.new
> Started POST "/discussions" for 127.0.0.1 at 2013-11-08 17:35:29 +0000
>   [1m [36mUser Load (3.4ms) [0m   [1mSELECT "users".* FROM "users" WHERE
"users"."id" = 8 LIMIT 1 [0m
>   [1m [35mContext Load (2.4ms) [0m  SELECT "contexts".* FROM "contexts" WHERE
"contexts"."id" = $1 LIMIT 1  [["id", "2"]]
>   [1m [36mRole Load (4.3ms) [0m   [1mSELECT "roles".* FROM "roles" WHERE
"roles"."name" = 'PC_USER' LIMIT 1 [0m
>   [1m [35mRole Load (3.8ms) [0m  SELECT "roles".* FROM "roles"
>   Rendered admin/shared/_quick_links.html.erb (2.1ms)
>   [1m [36mDiscussion Load (3.6ms) [0m   [1mSELECT DISTINCT discussions.* FROM
"discussions" INNER JOIN "discussions_users" ON
"discussions_users"."discussion_id" = "discussions"."id" INNER JOIN "users" ON
"users"."id" = "discussions_users"."user_id" WHERE (created_by_id = 8 OR
discussions_users.user_id = 8 OR users.account_id = 1) [0m
>

The clue might be in what is being rendered in the second request:

>   Rendered admin/shared/_quick_links.html.erb (2.1ms)

Maybe an AJAX request?
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2013-11-11 10:17
(Received via mailing list)
thanks for your reply.  Yes, thats what i thought originally but firebug
wasnt showing any ajax requests.  I will have to go through each bit and
find out exactly where the request is coming from, probably some
javascript
somewhere.
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2013-11-11 11:07
(Received via mailing list)
turns out it was this line of code in the layout

<link REL="SHORTCUT ICON" HREF="">


give me strength!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.