Monday, 15 March 2010

ruby on rails - Why do I get undefined method `each' allowing user the view own content? -


I am trying to get this work so that existing users can log in to see what they have posted I think that almost I have been cracked, but I got every error in an 'indispensable' method.

These are just two files I have edited:

_form.html.erb

  & lt; H1 & gt; Listing program & lt; / H1> & Lt; Table & gt; & Lt;% @ programs.each do | Program | & Gt%; & Lt; TR & gt; & Lt; Td> & Lt; H2 & gt; & Lt;% = program.title% & gt; & Lt; / H2 & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt;% = program.body% & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt;% = link_to 'Show', Program% & gt; | & Lt;% = link_to 'edit', edit_program_path (program)%> | & Lt;% = link_to 'deleted', program, method :: delete, data: {confirm: 'are you sure?' }% & Gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Table & gt; & Lt; Br / & gt; & Lt;% = link_to 'New Program', new_program_path% & gt;   

programs_controller.rb

  class program controller & lt; ApplicationController before_filter: authenticate_coach!, Except: => [: Show] #GET / Programs #GIT / Programs Jsn df index @ program = program.find (current_chitch [: id]) response_to do format | Format.html # index.html.erb format.json {json: @programs} End end # GET / Program / 1 # Received / Program / 1. Jason Df Show @ Program = ProgrammableFind (Param [: ID]) Response_to do | Format | Format.html # show.html.erb format.json {json: @program} End-End # GET / Program / New # GIT / Program / New. Jason Def New @ Program = Program.New Reply | Format | Format.html # new.html.erb format.json {render json: @program} End End # GET / Program / 1 / Edit def Edit Translation @program = Program.find (params [: id]) # POST / Program # End post / program.Jason DRF @ program = program.New (param [: program]) response_to do | Format | If the @ program. Save format.html {redirect_to @program, notice: 'The program was created successfully.' } Format.json {json: @program, status :: created, location: @program} and format.html {render action: "new"} format.json {render json: @ program.errors, status :: unprocessable_entity} end End end # PUT / Program / 1 # PUT / Program / 1. Jason Diff Update @ Program = ProgrammableFind (Param [: ID]) response_to do | Format | If @ program.update_attributes (params [: Program]) format.html {redirect_to @program, notice: 'The program was updated successfully.' } Format.json {head: no_content} else format.html {render action: "edit"} format.json {render json: @ program.errors, position :: unprocessable_entity} end-end # DELETE / programs / 1 # DELETE / program / 1. Delete Jason DF @ Program = ProgrammableFind (Param [: ID]) @program.DistroyReply_Fill. Format | Format.html {redirect_to programs_url} format.json {head: no_content} end and end   

There are different models currently in my program , which is the post of coach , And coach (user):

program.rb:

  class program & lt; ActiveRecord :: Base is_to: Coach validates_presence_of: title attr_accessible: body ,: title ,: coach_id end   

coach.rb:

  class coach & lt; ActiveRecord :: Base has_many: Program # includes developing modules by default. Available: #: token_authenticatable, confirmable, #: lockable, timeoutable and: Omniauthable devise: database_authenticatable,: registerable, recoverable ,: memoryable, trackable, validatable # Setup accessible (or preserved) for your model attr_accessible: Email, password: password _confirmation: random, first name, last name: coach # attr_accessible: title, body end   

If you need more details please let me know and I Give you

use

  @programs   

Or I think you should also change

  current_coach [: id]   

to

  Current_coach.id    

No comments:

Post a Comment