难以从另一个视图渲染部分

时间:2015-08-18 16:38:58

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

我在#import "ViewController.h" #import "ViewController.m" @interface ViewController () @end int RandomNumber; double ButtonTime; int RandomNumberButton; int score; @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { if ([[UIScreen mainScreen] scale] == 2.0) { if([UIScreen mainScreen].bounds.size.height == 667){ // iPhone retina-4.7 inch(iPhone 6) } else if([UIScreen mainScreen].bounds.size.height == 568){ // iPhone retina-4 inch(iPhone 5 or 5s) } else{ // iPhone retina-3.5 inch(iPhone 4s) } } else if ([[UIScreen mainScreen] scale] == 3.0) { //if you want to detect the iPhone 6+ only if([UIScreen mainScreen].bounds.size.height == 736.0){ //iPhone retina-5.5 inch screen(iPhone 6 plus) } //iPhone retina-5.5 inch screen(iPhone 6 plus) } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end @implementation Game{ } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)viewDidAppear:(BOOL)animated{ YellowCircle.hidden = YES; BlueCircle.hidden = YES; RedCircle.hidden = NO; score = 0; } -(void)ButtonGenerator{ RandomNumber = arc4random() % 100; if (RandomNumber>50) { ButtonTime = 3.0; } if (RandomNumber<50) { ButtonTime = 1.0 ; } if (RandomNumber>10) { ButtonTime = 4.0 ; } } -(void)setButtonEnabled{ BlueCircle.hidden = YES; } -(void)setYellowCircleEnabled{ YellowCircle.hidden = YES; } -(void)ButtonChanger{ RandomNumberButton = arc4random() % 100; if (RandomNumberButton>30) { BlueCircle.hidden = NO; [NSTimer scheduledTimerWithTimeInterval:ButtonTime target:self selector:@selector(setButtonEnabled) userInfo:nil repeats:NO]; RedCircle.hidden = YES; YellowCircle.hidden = YES; } if (RandomNumberButton<30) { YellowCircle.hidden = NO; [NSTimer scheduledTimerWithTimeInterval:ButtonTime target:self selector:@selector(setYellowCircleEnabled) userInfo:nil repeats:NO]; RedCircle.hidden = YES; BlueCircle.hidden = YES; } if (YellowCircle.hidden = YES, BlueCircle.hidden = YES, RedCircle.hidden = YES) { RandomNumber = 0; [self ButtonChanger]; } } - (IBAction)RedCircleButton:(id)sender { RandomNumber = 0; [self ButtonChanger]; score = score + 1; } - (IBAction)BlueCircleButton:(id)sender { } - (IBAction)YellowCircleButton:(id)sender { } @end 中渲染部分时遇到了问题。 Rails服务器日志中没有错误,视图中也没有输出。我删除了#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end @interface Game : UIViewController{ IBOutlet UIButton *RedCircle; IBOutlet UIButton *BlueCircle; IBOutlet UIButton *YellowCircle; } - (IBAction)RedCircleButton:(id)sender; - (IBAction)BlueCircleButton:(id)sender; - (IBAction)YellowCircleButton:(id)sender; @end 选项,结果仍然相同。即使我对部分硬编码,视图也不会显示信息,服务器日志也不显示错误。

应用/视图/ registry_requests / _index.html.erb

Rails 4.2.1

应用/视图/用户/ _admin.html.erb

as:

日志

<p><%= request.vehicle.make %></p>

3 个答案:

答案 0 :(得分:2)

尼斯!

确保@registry_requests

中定义了UsersController#show

答案 1 :(得分:0)

试试这个:

<% request.each do |one_request| %>
  <p><%= one_request.vehicle.make %></p>
<% end %>

答案 2 :(得分:0)

你应该尝试做这样的事情:

app / views / users / _admin.html.erb

<% @registry_requests.each do |request| %>
  <%= render partial: "registry_requests/index", :locals => {:registry_request => request} %>
<% end %>

应用/视图/ registry_requests / _index.html.erb

<p><%= registry_request.vehicle.make %></p>

由于@registry_requests是一个集合,因此您必须遍历它以获取每条记录,以便您可以找到每条记录make