0

(sorry for my english)

I'm trying my first rails web app. Here is my code:

Model:

class Movie < ActiveRecord::Base    

   attr_accessible :about, :title, :url

end

Controller:

class MoviesController < ApplicationController

  def show

    @movie = Movie.find(params[:id])

  end

  def update

    @mov = Movie.find(params[:id])

    if @mov.update_attributes(params[:id])

        redirect_to movies_path, :notice => "Your movie has been updated."

    else

        render "show"

    end  
  end


  def destroy

  end

end
  • and the View
    <%= form_for @movie do |m| %>
<center>
  <table>
    <td valign='middle' align='right'>
      Title:
    </td>
    <td>
      <%= m.text_field :title %>
    </td>
<tr>
    <td valign='middle' align='right'>
      Description:
    </td>
    <td>
      <%= m.text_area :about %>
    </td>
<tr>
    <td valign='middle' align='right'>
      URL:
    </td>
    <td>
     <%= m.text_field :url, :id => "url" %><input type='file' onchange="document.getElementById('url').value = this.value" />
    </td>
<tr>
    <td>
    </td>
    <td>
      <center>
        <%= m.submit %>
      </center>
    </td>
  </table>
</center>
<% end %>

so this is an update action and this give an error message after press the update form button error is:

undefined method `stringify_keys' for "15":String

so I try again with Movie.find(params[:id].to_i) and the output is:

undefined method `stringify_keys' for 15:Fixnum

thanks for answers, have a good day!=)

3
  • 1
    use Movie.find(params[:id].to_i) and use @mov.update_attributes(params[:movie]) instead of @mov.update_attributes(params[:id]) Commented Mar 19, 2013 at 12:18
  • 1
    May be issue with @mov.update_attributes(params[:id]) line. you have passed params[:id] but this is wrong you have to pass params[:movie]. Commented Mar 19, 2013 at 12:20
  • The line number comes in handy when looking at the error.... ;) Commented Mar 19, 2013 at 12:28

1 Answer 1

5
if @mov.update_attributes(params[:id])

Its because of the above line. Here you are trying to update the @mov attribute with the params[:id] which is wrong.

the update action in the controller should be as follow.

def update
  @mov = Movie.find(params[:id])
  if @mov.update_attributes(params[:movie])
    redirect_to movies_path, :notice => "Your movie has been updated."
  else
    render "show"
  end
end

Basically the update_attributes will check for hash as a parameter like below.

@mov.update_attributes(:about => "Sample About", :title => "Sample Title", :url => "Sample URL")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.