Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:58:02+00:00 2026-06-03T10:58:02+00:00

In my tickets.js.coffee : $.ajax ‘/comments/add’, type: ‘POST’, dataType: ‘html’ success: ( data )

  • 0

In my tickets.js.coffee:

$.ajax '/comments/add',
  type: 'POST',
  dataType: 'html'
  success: ( data ) ->
    alert 'success'

<%= form_for @comment, :url => user_ticket_message_comments_path( @user, @ticket, m ), :html => { :class => "add-comment", :id => "add-comment-" + @ticket.id.to_s } do |f| %>
  <%= f.label :body, "Add comment" %>
  <%= f.text_area :body %>
  <%= f.hidden_field :message_id, :value => m.id %>
  <%= f.submit "Add comment" %>
<% end %>

Comments table:

id | message_id | body
----------------------

CommentsController:

def create
  @comment = params[:comment]
  @comment.save
end

My routes.rb:

resources :messages do
  resources :comments
end

I get this error:

undefined method `save' for {"body"=>"awef", "message_id"=>"15"}:ActiveSupport::HashWithIndifferentAccess

Comment belongs to a Message and Message has many comments.

Where should I look to fix this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:58:04+00:00Added an answer on June 3, 2026 at 10:58 am

    params[:comment] is a Hash, not a Comment object, and thus can’t be “saved”. You need to create a new Comment object and assign each attribute to it, then save the Comment object:

    def create
      @comment = Comment.new(params[:comment])
      @comment.save
    end
    

    Depending on how “new” your app is, config.active_record.whitelist_attributes may be set to true, in which case the above will give you a security error and you should read the Rails Guides on Mass-Assignment for more information about how to properly assign attributes (you should actually read it either way).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am playing with an idea that would allow people to add tickets to
I got the problem similar to this post here: https://rails.lighthouseapp.com/projects/8994/tickets/106-authenticity_token-appears-in-urls-after-ajax-get-request routes.rb map.namespace(:admin, :active_scaffold =>
I have an HTML table of tickets listings (e.g. http://seatgeek.com/event/show/23634/buffalo-bills-vs-tennessee-titans/ ). I'd like to
My app has Tickets, and a ticket can be resolved. I can POST via
It's very painful to add multiple tickets to Trac or to have it as
Here is my Tables data Tickets +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + id | tic_files | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +
Is it possible to assign tickets or add labels to github issues in a
I have a GridView using LinqDataSource to populate data from table Tickets . The
<tickets type=array> <ticket> <assigned-user-id type=integer>123</assigned-user-id> <closed type=boolean>true</closed> <creator-id type=integer>177522</creator-id> <number type=integer>306</number> <state>resolved</state> <tag nil=true/>
I am creating a tickets opened vs resolved per week gadget that reports back

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.