简体   繁体   English

渲染视图

[英]Rendering a view

I have partials calling from a bootstrap sidebar. 我有一个从引导侧栏调用的局部函数。 Each tab points using bootstrap js to a partial. 每个选项卡使用bootstrap js指向部分。 When I do an action and the page refreshes it brings me back to the default url courses/dashboad. 当我执行操作并刷新页面时,它带我回到默认的URL课程/仪表板。

How can I put the div id into a parameter so that the redirect will stay on the partial view instead of going back to the default dashboard partial of the page please? 如何将div id放入参数中,以便重定向将保留在部分视图上,而不是返回页面的默认仪表板部分? So essentially want it to do 所以本质上是要它做

render 'courses/my_courses'

after the action is complete. 操作完成后。 Here is my view page and controller code. 这是我的视图页面和控制器代码。 It's failing with a template missing error but i essentially want to redirect to the dashboard and then render this partial. 它因模板丢失错误而失败,但是我本质上想重定向到仪表板,然后局部渲染。 Thanks lads. 谢谢伙计们。

Controller 调节器

def course_complete
    @course = Course.find(params[:id])
    @course.update_attributes(complete: true)
    flash[:notice] = "Course name #{@course.title} now marked as complete"
    render 'courses/my_courses' 
end

def dashboard
    my_courses
    @company = @user.company
end

View 视图

    <div role="tabpanel" class="tab-pane" id="my_courses">
    <div class="dash-panel">
        <h3><i class="fa fa-address-card-o"></i> My Courses</h3>
        <span>All your courses listed below</span>
    </div>
    <div class="courses-panel">
        <%= render 'courses/my_courses' %>
    </div>

Add redirect_to in your course_complete method and render partial in dashbaord method like this 在您的course_complete方法中添加redirect_to,并在dashbaord方法中渲染部分,就像这样

def course_complete
    @course = Course.find(params[:id])
    @course.update_attributes(complete: true)
    flash[:notice] = "Course name #{@course.title} now marked as complete"
    redirect_to your_dashboard_path
end

def dashboard
    my_courses
    render 'courses/my_courses' 
    @company = @user.company
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM