Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

creating an application to import a csv file(help me

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
View previous topic :: View next topic  
Author Message
blackcaps



Joined: 31 Mar 2010
Posts: 1

PostPosted: Wed Mar 31, 2010 4:54 am    Post subject: creating an application to import a csv file(help me Reply with quote

hi actually i am creating an application to import a csv file to
database. but onn running that application ai'am getting errors like
this

NoMethodError in ImportsController#new


undefined method `login_required' for #<ImportsController:0xb6d84b5c>

and this error too


Processing ImportsController#new (for 127.0.0.1 at 2010-03-31 09:38:19)
[GET]

NoMethodError (undefined method `login_required' for

#<ImportsController:0xb6d03f70>):



ma controller is here



class ImportsController < ApplicationController
before_filter :login_required #protect controller from anonymous users


def new
@import = Import.new
end

def create
@import = Import.new(params[:import])

respond_to do |format|
if @import.save!
flash[:notice] = 'CSV data was successfully imported.'

format.html { redirect_to(@import) }
else
flash[:error] = 'CSV data import failed.'
format.html { render :action => "new" }
end
end
end


def show
@import = Import.find(params[:id])
end

def proc_csv
@import = Import.find(params[:id])
lines = parse_csv_file(@import.csv.path)
lines.shift #comment this line out if your CSV file doesn't contain

a header row
if lines.size > 0
@import.processed = lines.size
lines.each do |line|
case @import.datatype
when "releases"
new_release(line)
end

end
@import.save
flash[:notice] = "CSV data processing was successful."
redirect_to :action => "show", :id => @import.id
else

flash[:error] = "CSV data processing failed."
render :action => "show", :id => @import.id
end
end

private

def parse_csv_file(path_to_csv)

lines = []

#if not installed run, sudo gem install fastercsv
#http://fastercsv.rubyforge.org/
require 'fastercsv'

FasterCSV.foreach(path_to_csv) do |row|

lines << row
end
lines
end

def new_release(line)
params = Hash.new
params[:release] = Hash.new
params[:release]["title"] = line[0]
params[:release]["rdate"] = line[1]

params[:release]["body"] = line[3]
params[:release]["notes"] = line[4]
release = Release.new(params[:release])
release.save
end

end

this is ma model



class Import < ActiveRecord::Base
# Paperclip
has_attached_file :csv
validates_attachment_presence :csv
validates_attachment_content_type :csv, :content_type =>
['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.*','text/anytext','text/plain']

end


anyone pls help me
Back to top
View user's profile Send private message
umamahesh_nyros



Joined: 17 Jul 2007
Posts: 231
Location: KAKINADA

PostPosted: Mon Apr 05, 2010 5:51 am    Post subject: Reply with quote

Hi blackcaps,

This error is due to "before_filter :login_required" . you have added an before filter in you controller and the method "login_required" in not defined in that controller. so it may check for the method in application controller. i think you have not mentioned the "login_required" method in the application controller. so do cross check and make sure to have "login_required" method in application controller .

Thank You,
Uma.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Chat utility in a ROR application
0 shobana 2 Thu Sep 09, 2010 9:45 am
shobana View latest post
No new posts How to customize Google Maps InfoWindow using ym4r_gm
0 kalyanallampalli 54 Thu Sep 02, 2010 5:34 pm
kalyanallampalli View latest post
No new posts Drag and Drop file upload
0 umamageshwari 51 Wed Sep 01, 2010 9:36 am
umamageshwari View latest post
No new posts Flex On Rails
0 Raghu 48 Wed Sep 01, 2010 3:00 am
Raghu View latest post
No new posts MongoDB
0 Raghu 45 Tue Aug 31, 2010 3:30 pm
Raghu View latest post
No new posts Problem with Dreamweaver / java error
3 Raja 37 Tue Aug 31, 2010 3:24 pm
Raghu View latest post
No new posts Generating Model
0 phani.galla 44 Tue Aug 31, 2010 2:09 pm
phani.galla View latest post
No new posts Hide Panels using JQuery
0 Anu 48 Tue Aug 31, 2010 1:50 pm
Anu View latest post
No new posts Load a text file using ajax in jquery
0 Anu 38 Tue Aug 31, 2010 1:39 pm
Anu View latest post
No new posts Generating Migrations
0 phani.galla 31 Tue Aug 31, 2010 1:38 pm
phani.galla View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More