我正在尝试在页面上创建一个链接,该链接将转到具有正确ID的页面。链接所在的页面位于:import com.vinay.timeclass.exceptions.InvalidTimeException;
/**
* @author Dell
*
*/
public class Time {
private int hour;
private int minute;
public Time() {
hour = 0;
minute =0;
}
public Time(int hour, int minute) throws InvalidTimeException {
if(hour > 24 || minute > 60)
throw new InvalidTimeException(" Hour cannot be greater than 24 and minute cannot be greater than 24 ");
if(hour >=1 && hour<=23)
this.hour = hour;
else
this.hour = 0;
if (minute >=0 && minute <=59) {
this.minute = minute;
} else {
minute = 0;
}
}
@Override
public String toString() {
StringBuilder timeBuilder = new StringBuilder();
if(hour < 10 && minute < 10) {
timeBuilder.append("0").append(hour).append(":").append("0").append(minute);
}
else if (hour < 10 && minute > 10) {
timeBuilder.append("0").append(hour).append(":").append(minute);
}
else if (hour > 10 && minute < 10) {
timeBuilder.append(hour).append(":").append("0").append(minute);
}else if(hour > 10 && minute > 10) {
timeBuilder.append(hour).append(":").append(minute);
}else if(hour == 0) {
if(minute < 10)
timeBuilder.append("0").append(hour).append(":0").append(minute);
else
timeBuilder.append(hour).append(":").append(minute);
}else if (minute == 0) {
if(minute < 10)
timeBuilder.append("0").append(hour).append(":0").append(minute);
else
timeBuilder.append(hour).append(":0").append(minute);
}
return timeBuilder.toString();
}
public int getHour() {
return hour;
}
public void setHour(int hour) throws InvalidTimeException{
if(hour>24)
throw new InvalidTimeException("Hour cannot be greater than 24");
this.hour = hour;
}
public int getMinute() {
return minute;
}
public void setMinute(int minute) throws InvalidTimeException{
if(minute>60)
throw new InvalidTimeException("Minute cannot be greater than 60");
this.minute = minute;
}
public String convert(){
StringBuilder timeBuilder = new StringBuilder();
if(hour > 11) {
if(hour == 12) {
timeBuilder.append(hour).append(":").append(minute).append(" PM");
}else if(hour > 12) {
timeBuilder.append(hour-12).append(":").append(minute).append(" PM");
}
}else if(hour == 0) {
timeBuilder.append(hour+12).append(":").append(minute).append(" AM");
}else {
timeBuilder.append(hour).append(":").append(minute).append(" AM");
}
String timeString = timeBuilder.toString();
if(minute < 10) {
timeString = timeString.substring(0, timeString.length()-4)+"0"+minute+" "+timeString.substring(timeString.length()-2, timeString.length());
}
return timeString;
}
public void increment() {
if(hour== 23 && minute == 59) {
hour = 0;
minute = 0;
}else {
minute ++;
if(minute == 60) {
hour++;
minute = 0;
if(hour == 24) {
hour =0;
}
}
else if(hour == 24) {
hour = 0;
}
}
}
}
。单击链接后,页面应重定向到http://localhost:3000/quotes/9942/marketingScheduleShell
。
我希望这些工作能够正常进行,但是当我尝试下面的代码时,它只带我进入http://localhost:3000/quotes/9942/
页面。
/quotes/
如何使用我单击的报价对象的ID转到该对象的正确页面?
答案 0 :(得分:1)
您唯一需要的是link_to
method
link_to('Show', quote_path(@quote))
另外阅读一些指南可以为您节省很多时间:http://guides.rubyonrails.org/