exemple sur le cinéma (rails)


K

kungfu-free

#Movies.rb:
def deleted_roles=(values)
roles.find(*values).each(&:destroy)
end





#Role.rb:

class Role < ActiveRecord::Base
belongs_to :movie
belongs_to :person

validates_presence_of :movie_id, :person_id, :name

def to_s
[person.full_name, name].join(' - ')
end
end

movies_controller.rb:
65 def update
66 @movie = Movie.find(params[:id])
67 debugger
68
69 respond_to do |format|
70 if @movie.update_attributes(params[:movie])
71 flash[:notice] = 'Movie was successfully updated.'
72 format.html { redirect_to(@movie) }
73 format.xml { head :eek:k }
74 else
75 format.html { render :action => "edit" }
76 format.xml { render :xml => @movie.errors, :status
=>:unprocessable_entity }
77 end
78 end
79 end
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top