我正在尝试在页面控制器中创建一个变量 latitude
,其值为long_lat_parser.lon
。我希望将变量发送到 home.html视图 !!
PagesController 挂钩到主页page.html以查看我的变量:
class PagesController < ApplicationController
def place_params
long_lat_parser = LongLatParser(image)
{place_attributes: {longitude: long_lat_parser.lon, latitude: long_lat_parser.lat}}
end
def home
@post = Post.new
@posts = Post.all
@places = Place.all
@place = Place.new
@post = current_user.posts.build(post_params.merge(place_params))
#@latitude = Post.save_image_exif(params[:latitude])
end
lotlangparser模型:
class LotLangParser
after_create :initialize
def initialize(image)
@image = image
@exif_data = MiniExiftool.new(image.queued_for_write[:original].path)
end
def lat
parse_latlong(exif_data['gpslatitude'])
end
def lon
parse_latlong(exif_data['gpslongitude'])
end
private
def parse_latlong(latlong)
return unless latlong
match, degrees, minutes, seconds, rotation = /(\d+) deg (\d+)' (.*)" (\w)/.match(latlong).to_a
calculate_latlong(degrees, minutes, seconds, rotation)
end
def calculate_latlong(degrees, minutes, seconds, rotation)
calculated_latlong = degrees.to_f + minutes.to_f/60 + seconds.to_f/3600
['S', 'W'].include?(rotation) ? -calculated_latlong : calculated_latlong
end
end
总而言之,我想把这个lat与indiviualy和long一起放进html视图!我将如何将其发布到视图中? <%= long_lat_parser.lon %>
??