我有用于后端的Ruby on Rails 5.2 API和用于前端的Angular 6。用户从另一个网站登录到该网站。我有subscription_controller,它从第一个网站获取数据,还有user_controller,它具有要使用的前端用户的所有详细信息。 我想使用相关ID从subscription_controller调用user_controller的show def。
subscription_controller
ggplot(summarized) +
geom_raster(aes(x = x_grid, y = y_grid, fill = z_brk)) +
geom_label(aes(x = min_x, y = y_grid, label = brk_num), data = labels, size = 3, hjust = 0.5) +
theme_void() +
theme(legend.position = "none", panel.background = element_rect(fill = "gray40")) +
coord_fixed() +
scale_fill_brewer(palette = "PuBu")
user_controller
class SubscriptionsController < ApiController
def login
name = params["name"]
email = params["email"]
organization_name = params["organization"]
current_user = User.find_by(email: email)
if current_user
##### render show JSON of user_controller for current_user #####
puts "redirect to frontend"
else
current_user = User.create(name: name, email: email)
subscription_id = find_the_right_subscription(email, organization_name)
current_user.subscription_id = subscription_id
current_user.save
##### render show JSON of user_controller for current_use #####
puts "redirect to frontend"
end
end
def find_the_right_subscription(email, organization_name)
email_domain = email.split("@").last
found_subscriptions = Subscription.where("organization like ? or domain like ?","%#{organization_name}%","%#{email_domain}%")
if found_subscriptions.empty?
subscription = Subscription.find_by(name: 'Default Subscription')
else
subscription = found_subscriptions.first
end
return subscription.id
end
end