我很好奇是否有人使用过UnderC,Cint,Cling,Ch或任何其他C++解释器并且可以分享他们的经验.
随着最近升级到Rails 4,使用类似下面的代码更新属性不起作用,我收到一个ActiveModel::ForbiddenAttributes错误:
@user.update_attributes(params[:user], :as => :admin)
Run Code Online (Sandbox Code Playgroud)
用户在模型中具有以下attr_accessible行:
attr_accessible :role_ids, :as =>admin
# or any attribute other than :role_ids contained within :user
Run Code Online (Sandbox Code Playgroud)
你如何在Rails 4中完成同样的任务?
ruby-on-rails attr-accessible activemodel strong-parameters ruby-on-rails-4
我将以下表放在名为Student(/ Student/Details/1)的控制器中的视图中:
    @foreach (var item in Model.Enrollments)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Course.Title)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Grade)
            </td>
        </tr>
    }
Run Code Online (Sandbox Code Playgroud)
我想将每个表定义变成一个链接,将我带到名为Course(/ Course/Details/1)的控制器中的视图.
我尝试过以下方面的事情:
@Html.ActionLink(Html.DisplayFor(modelItem => item.Course.Title, "Details", "Course"))
Run Code Online (Sandbox Code Playgroud)
代替
@Html.DisplayFor(modelItem => item.Course.Title)
Run Code Online (Sandbox Code Playgroud)
哪个不编译.如何正确显示我的模型标题以及引用标题详细信息的链接?
我想展示一个画廊,products其中包括既可以出售也可以出售的产品.只有我希望products待售的那些出现在列表的前面,而非待售的对象将出现在列表的末尾.
我完成此任务的一个简单方法是创建两个列表,然后合并它们(一个on_sale?对象列表和一个not on_sale?对象列表):
available_products = []
sold_products = []
@products.each do |product|
  if product.on_sale?
    available_products << product
  else
    sold_products << product
  end
end
Run Code Online (Sandbox Code Playgroud)
...但是对于我现有应用程序的结构,由于我的代码奇怪,这需要过多的重构(我失去了我的分页,我宁愿不重构).如果有一种方法可以通过我的product模型方法对现有的对象列表进行排序,on_sale?这会返回一个布尔值.
是否可以更优雅地遍历现有列表并通过rails中的true或false值对其进行排序? 我只是问,因为有很多我不知道隐藏在这个框架/语言(ruby)中,我想知道他们是否在我之前完成了工作.
我正在尝试使用ASP.NET MVC 3中的成员资格提供程序设置和保存电子邮件更改.我不知道如何在成员资格提供程序中正确设置和更改电子邮件属性.
MSDN似乎建议使用MembershipUser.Email属性,"获取或设置成员资格用户的电子邮件地址",但我不知道如何使其正常运行.
我试图使用此代码:
// change email
MembershipUser u = Membership.GetUser(User.Identity.Name);
u.Email = email; // Is this working as expected?
u.Save();  // this line doesn't do anything - what should it be?
db.Save();  <-- that is what I would do with ordinary database changes, but I don't know what context to use for Membership Provider changes. . .
Run Code Online (Sandbox Code Playgroud)
编辑:
我想到了:
// change email
MembershipUser u = Membership.GetUser(User.Identity.Name);
u.Email = email;
System.Web.Security.Membership.UpdateUser(u);
Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-membership membership-provider asp.net-mvc-3
我有以下rspec测试工作:
  it "redirects to the created api_key" do
    post :create, :api_key => {:api_identifier => "asdfadsf", :verification_code =>
        "12345"}
    response.should redirect_to(ApiKey.last) #(or any other test function)
  end
Run Code Online (Sandbox Code Playgroud)
但我使用工厂女孩所以我不必手动创建api_keys.
我如何复制上述功能,但使用工厂女孩?
使用:
  it "redirects to the created api_key" do
    test = FactoryGirl.build(:api_key)
    post :create, :api_key => test
    response.should redirect_to(ApiKey.last) #(or any other test function)
  end
Run Code Online (Sandbox Code Playgroud)
要么:
  it "redirects to the created api_key" do
    post :create, FactoryGirl.build(:api_key)
    response.should redirect_to(ApiKey.last) #(or any other test function)
  end
Run Code Online (Sandbox Code Playgroud)
:api_key当我到达控制器时,给我值的空值.
作为参考,这是我的测试正在测试的创建操作:
def create
  @api_key = …Run Code Online (Sandbox Code Playgroud) 我希望AntiForgeryTokens在每个HttpPost Action上使用ActionFilter,该ActionFilter位于ControllerBase每个其他控制器继承的控制器中.
我想通过创建一个ActionFilter来实现这一点,该ActionFilter从中继承ValidateAntiForgeryToken一个参数,该参数告诉它将HTTP谓词应用到哪个.然后,我想要应用该过滤器,   ControllerBase以确保AntiForgeryToken在整个站点上检查每个POST操作.
我正在研究使用这个解决方案,但是
AuthorizationContext Constructor (ControllerContext)是一个过时的构造函数,我不知道如何使用推荐的方法重建代码AuthorizationContext(ControllerContext controllerContext, ActionDescriptor actionDescriptor).  
默认情况下它似乎不使用AntiForgeryToken,因为我收到以下错误:A required anti-forgery token was not supplied or was invalid每次发布后操作.
我应该如何重写ActionFilter以满足当前的非过时标准并在每个[HttpPost]动词上正确使用防伪标记?
我是否必须在每种形式中都包含一个防伪标记(我在想)?(而不是自动生成 - 不要笑,我很好奇) 更新:正如评论中指出的那样; 是的,这必须在每个表格中完成.
以下是我的ControllerBase中的代码供参考:
[UseAntiForgeryTokenOnPostByDefault]
public class ControllerBase : Controller 
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class BypassAntiForgeryTokenAttribute : ActionFilterAttribute
    {
    }
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class UseAntiForgeryTokenOnPostByDefault : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext) …Run Code Online (Sandbox Code Playgroud) asp.net-mvc http-verbs action-filter antiforgerytoken asp.net-mvc-3
我有一个记录模型和控制器:
require 'open-uri'
class Record < ActiveRecord::Base
  has_attached_file :record,
                    :s3_protocol => :https,
                    :url => ':s3_domain_url',
                    :path => '/record/latest/:basename.:extension'
  has_attached_file :archive_record,
                    :s3_protocol => :https,
                    :url => ':s3_domain_url',
                    :path => '/record/archive/:basename.:extension'
end
class RecordsController < ApplicationController
  def upload_record
    @error = nil
    previous_record = Record.where(:is_archive => false).first
    @new_record = Record.new(record_params)
    if @new_record.save
      unless previous_record.blank?
        if create_archive(previous_record)
          previous_record.destroy
        end
      end
      @success = I18n.t('record.success.record_uploaded')
    else
      @error = find_error(@new_record)
    end
    respond_to do |format|
      format.js {
        render :layout => false
      }
    end
  end 
  def change_record
    previous_record = …Run Code Online (Sandbox Code Playgroud) 我已经开发了我的第一个大型(对我来说)MVC项目,现在已经有几个月了,事情变得非常难以导航.
我一直在摒弃重构,并且正在寻求"最佳实践"的现代示例,只要保持控制器的精简并将所有数据移动到模型中.
我读过这篇文章详细讨论了一些内容,但没有提供示例项目.
这里发布的大多数"最佳实践"主题都倾向于链接到MVC音乐商店或Nerd Dinner项目,但与此同时,评论倾向于说他们更多是"初学者指南",而不是"最佳实践"的例子.
有谁知道任何展示适当开发结构的最新开源MVC项目?
注意:我想学习解决的一个典型问题:我的控制器很长并且充满了驱动网站的代码 - 我需要将这些代码移到仅由控制器引用的方法中.我在哪里抛出所有这些方法?
下面是一个来自控制器的代码示例,如其中一个回复的评论所示.我如何将这些信息移到我的ViewModel上?(我在下面包含了ViewModel):
控制器:
public ActionResult AttendanceView(int id)
{
    //
    // Generates list of Attendances specifically for current Course
    var attendanceItems = db.Attendance.Where(s => s.CourseID == id);
    List<Attendance> attendanceItemsList = attendanceItems.ToList();
    // End of generating list of Attendances
    //
    // Generates list of Students in alphabetical order sorted by LastName
    var student = attendanceItemsList.Select(a => a.Student).Distinct().OrderBy(s => s.LastName);
    List<Student> StudentList = student.ToList();
    // End of generating list of Students
    //
    // …Run Code Online (Sandbox Code Playgroud) 有很多人有类似的问题,我过去曾经在其他机器上遇到其中一个并且没有一个解决方案似乎有效 - 我似乎也有比其他有类似问题的人有不同的错误:
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.
    /Users/username/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -r ./siteconf20150412-25981-y7cvt6.rb extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling accessor.cc
clang: warning: argument unused during compilation: '-rdynamic'
In file included from accessor.cc:1:
In file included from ./rr.h:6:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:265:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__bit_reference:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628:
In …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
ruby ×2
actionlink ×1
activemodel ×1
activerecord ×1
amazon-s3 ×1
c# ×1
c++ ×1
controller ×1
factory-bot ×1
http-verbs ×1
interpreter ×1
osx-yosemite ×1
paperclip ×1
razor ×1
rspec ×1
sorting ×1
therubyracer ×1