How to parse a text file successfully in rails -


i'm new rails, , trying set simple app parses list database that's displayed in app.

the list have text file of films john williams scored, , actual parsing goes fine, when trying put database hits error. (nomethoderror).

parser file:

rails_env = 'development' require file.expand_path('../environment', __file__)  f = file.open("films.txt")   f.each |line|     title = line[0,line.index('(')]     year = line[line.index('('),line.rindex(')')]     puts title   puts year   puts '/'   @film = film.new @film.title = title @film.year = year @film.save end f.close 

it says error undefined method "title=" , i'm not sure means.

this own interest feel free link me readings or whatever, solution nice too.

cheers.

edit:

schema:

activerecord::schema.define(version: 20141221022528)    create_table "films", force: true |t|     t.datetime "created_at"     t.datetime "updated_at"     t.string "title"     t.string "year"    end  end 

model:

class film < activerecord::base      def index        @film = film.all       @film.title        @film.year    end  end 

films_controller.rb:

class filmcontroller < applicationcontroller     def index        @films = film.all       @films.title        @films.year    end   def film_params       params.require(:film).permit(:title, :year)     end     def new     @films = film.new   end  end 


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -